Learning something new everyday

Enriching those around me with this wealth

WordPress: How to Display the Parent Page Title in Your Title Meta Tag

In a project I’m working on at the moment, The page structure is set up using 5 main pages, and then each have their respective sub-pages. For SEO purposes, I wanted my <title> meta tag to display the page title and it’s parent page title if the current page was a child page, i.e.:

<title>Page Title</title> or <title>Parent Page Title — Page Title</title>

So after doing a little searching and combining some code, this is what I came up with:

<title><?php
if($post->post_parent) {
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
?> &#8212; <?php } ?><?php wp_title(''); ?></title>

One Response to “WordPress: How to Display the Parent Page Title in Your Title Meta Tag”

  1. Web Designer Kent Says:

    Ive been working on CSS based sites for sometime but still get the odd error in firefox ! wish they just played ball the same when designing, would make life a whole lot easier for everyone involved… but then that would be to simple and obvious…lol

Leave a Reply