
If you use pages and subpages or posts and parent posts on your WordPress blog, it should be a good idea to display parent page/post title while on a child page. Here’s a code to do that job easily.

If you use pages and subpages or posts and parent posts on your WordPress blog, it should be a good idea to display parent page/post title while on a child page. Here’s a code to do that job easily.
To achieve this recipe, simply edit your page.php file and paste the following code where you'd like your parent page title to be displayed:
<?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?>
That's all. Also, this code should be some inspiration for creating breadcrumbs. See you tomorrow!
5 Responses
Pretty awesome thanks for the help
Cheers
Thank you!
I had some code that worked but when there were parent pages with two words it place a hyphen between them. This is much cleaner and no hyphen!
Thank you very mach,
very simple and clean code
Thank you
An if-function would also be helpful
Doesnt work if you have more than 2 level.
Like:
Page 1 -> Page A -> Page Level 3 -> Sub Page (level 4).
Trackbacks: