固定ページの最上位のタイトルを取得する方法
functions.php
function my_toplevel_title() {
global $post;
if(is_page()):
if($post -> post_parent != 0 ): //親がいる場合
$ancestor = array_pop(get_ancestors($post->ID, 'page'));
return esc_html(get_the_title($ancestor));
else: //親がいない場合は自身を返す
return esc_html($post->post_title);
endif;
endif;
}

本サイトの内容に誤りや不正確な記述がある場合やサンプルに基づくいかなる結果も一切の責任を負いかねますので、あらかじめご了承ください。