Add Dates to your <titles>

January 12, 2010

One of the things I noticed from my old blog was that old content can often get mistaken for new content by people who do not read your blog regularly. The main reason is that people can see, right in search results, how old the post is and how significant it might be. Check out this image:

example image

There are two search results here -- one that has a date and one that does not. The first one doesn't give the user any indication of how old that page might be, while you immediately know that the second search result was created on Dec 14, 2009. six months from now, that page might be irrelevant, users can decide for themselves whether they want to visit the page.

If you're using CakePHP like I am, this is very easy. In your posts controller's view() function, add this line of code. (Assuming that $postdata is the database entry.)

$this->pageTitle = ''.$postdata['Post']['title'].' - '.date('M j, Y', strtotime($postdata['Post']['published']));

And then in your app_controller.php file, do something like this with the beforeRender() function. beforeRender gets called automatically by Cake just before any view begins to render.

function beforeRender() {
    //create page title
    $title = 'Zastica ';

    if(!empty($this->pageTitle)) {
        $title .= ' &bull; '.$this->pageTitle;
    else {
        $title .= ' &bull; '.$this->params['action'];

    $this->pageTitle = ucwords($title);

What happens is that if you set a pageTitle in any controller or function, it is automatically formatted, and your site's name added. If you don't set it, it just becomes "SiteName • $action". As you can see in the image, "Zastica • Seattle" vs. "Zastica • Business Card 1.0 - Dec 14, 2009".

The bottom line is that it helps users figure out how relevant your site's content is from search results.