How to: Get parent page/post title

January 28, 2009 at 8:24 am

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!

Tags: