how to get parent page title in wordpress

If want to get parent page title in wordpress and show in wordpress then use following code snippet in your theme you can easily get the parent page title.

how to get parent page title in wordpress

Normally what I would do is check $post->parent and if 0 then return page title else return title of page above. Problem is that $post->parent will only go back one level. I need to use some sort of recursive function that keeps going back until $post->parent == 0.

Add following code in to your wordpress theme, functions.php file and that sit. you will done.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
 global $post;
 $parent_title = get_the_title($post->post_parent);
 echo $parent_title;
?>

Using above code you can easily print the page title in wordpress theme.

how to get parent page title in wordpress

how to get parent page title in wordpress

Add a Comment

Your email address will not be published. Required fields are marked *