how to get the parent page title in wordpress

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

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.