Extend your Page Title using the Drupal breadcrumb path
If you use breadcrumbs in your website to help visitors navigate, you could also use these to extend the functionality of your META <title> tag. Let me give you an example of where this can be useful. Suppose you have a menu structure like:
- Home
- Updates
- Press
- Blog
- It's going great!
- What are we doing today?
- Contact
- Address
- Route
If we are on a blog node, the $site_title (META Title) will be 'What are we doing today? | Site Name'. We can extend this to something more useful like 'Blog » What are we doing today?'. And on your Press overview page, the title will be 'Updates » Press'. Much better!
To do so, open your page.tpl.php and insert the following code above the <title> tag:
<?php
$crumbs = drupal_get_breadcrumb();
$lastCrumbItem = $crumbs[(sizeof($crumbs)-1)];
$pagetitle = ( trim($title) == trim($lastCrumbItem) ) ? $crumbs[(sizeof($crumbs)-2)] : $lastCrumbItem;
$pagetitle = strip_tags($pagetitle);
$head_title = $pagetitle ? $pagetitle . ' » ' . $head_title : $head_title;
?>
Post new comment