get_the_title() gets printed out twice
Your conditional is always true. To understand why, consider what happens in this function when there is no post parent: function get_top_ancestor_id() { global $post; // no parent so this doesn’t run: // if($post->post_parent) { // $ancestors = array_reverse(get_post_ancestors($post->ID)); // return $ancestors[0]; // } return $post->ID; } Which simplifies to: function get_top_ancestor_id() { global $post; … Read more