WordPress tutorials: Get parent page title

Wpsnipp -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.Adding this PHP code to your wordpress theme will return the title of the parent page.

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;
?>

Be Sociable, Share!

Leave a comment