Althougt it may sound simple to advanced WordPress coders, I had many requests from people working with WordPress as a CMS and wanting to be easily able to display parent page title on a subpage.
Althougt it may sound simple to advanced WordPress coders, I had many requests from people working with WordPress as a CMS and wanting to be easily able to display parent page title on a subpage.
Nothing hard at all: Just paste the following code where you'd like to display the parent page title:
<?php
if($post->post_parent) {
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
} else {
wp_title('');
}
?>
That's all! Quick and easy, as we like
This recipe has been submitted by Wes Bos. Have WordPress skills? Feel free to contribute to WpRecipes!
3 Responses
Great!! Thanks alot!
Is there a way to make a link too? (link to itself – the parent)
Thanks for the tip! Quick question: Any idea how would you write the function if you wanted to show the root parent page on a grandchild page? I’ve been tinkering, but no cigar (yet).
Thank you!
Can you explain how can I display not the parent’s titile, but parent’s menu label?
I’m using All In One Seo pack, where I use special field for menu — its much shorter comparing to long titles.
Trackbacks: