WordPress Tip – Print parent page title and if there is no parent, print current page title.

Got this requirement on one my projects to show the Parent Page Title if there is a parent page and if there is no parent page to show the current page title. To do that use the following code,

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