Get the Title of the Parent Page; If No Parent, Show this Page’s Title

This snippet is from a book project – the book title needed to be shown on all subsequent chapters, unless it was the main book page. Here’s the snippet that does it:

<?php echo empty( $post->post_parent ) ? get_the_title( $post->ID ) : get_the_title( $post->post_parent ); ?>

One thought on “Get the Title of the Parent Page; If No Parent, Show this Page’s Title

Leave a Reply

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

Ready for a refreshing experience on your next website design?