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;
?> — <?php } ?>
<?php wp_title(''); ?>
</title>
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
Thanks! This helped.
thanks! been looking for a way to display the page parent title.
Thanks for this cool tip.. it helps me when i create tabs of subpages from a parent page.
Thanks! exactly what was looking for
Magic, thankyou
where do I put the code? I’m also a little confused with each post I do. Am I going to have to change this code everytime I make a new child page.
This should go in the header.php template between the tags.
Tammy to the rescue, again!
This also works nice if you need to display the title on the page itself between heading tags.
By the way this post is #1 in Google for “wordpress display name of parent page”