Inherit Parent / Ancestor Page Title

Useful way to grab the title from the page ancestor, and setup child page titles.

$current = $post->ID;
$parent = $post->post_parent;
$grandparent_get = get_post($parent);
$grandparent = $grandparent_get->post_parent;

if ($root_parent = get_the_title($grandparent) !== $root_parent = get_the_title($current)) {

    echo get_the_title($grandparent); 

} else {

    echo get_the_title($parent); 


Sourced here.

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.