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;
?> — <?php } ?><?php wp_title(''); ?></title>
July 21st, 2008 at 10:48 pm
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