lynk
 
 
 
 
23. December 2005

Hacks

 

Add the parent page name to the title tag on sub-pages

The page you are currently viewing is a sub-page of the page “Wordpress”.
The regular title would look like “lynk » Hacks”. This is fine because the page is about Hacks, but it doesn’t tell you by the title that it’s about Wordpress Hacks.
“lynk » Wordpress » Hacks” is much better for search engine results.

 

Replacement for <title></title> in header.php:

<title><?php
bloginfo('name');

if($wp_query->post->post_parent!=0)
{
$_post_parent = get_post($wp_query->post->post_parent);
echo " &raquo; ".$_post_parent->post_title;
}

wp_title();
?></title>

    2 Responses to “Hacks”

  • Tedinoz

    Thank you. That’s a neat hack and I’m using it now.

    FWIW, my pages go down 3 levels, and once you hit the bottom, the parent page has gone from the title – but that’s something I can easily live with.

    Funnily enough as I was writing this I looked at my breadcrumbs and saw the remarkable similarity between how they work and how the title should look. Maybe that will be my first attempt at a plugin – though it seems a bit harsh to rip off all the hard work that others have done.

    Anyway, thanks.

    Ted

  • Artem Saltanov

    Really helpful. Thank you very much!

    Realno pomoglo. Bolschoe spasibo!


Leave a Reply




Creative Commons License

Home

Pages

Categories


81 weeks ago

Propaganda