Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick, small function to check if your page is currently the nth child
<?php
/**
* is_nth_level_page
*
* Quick, small function to check if your page is currently the nth child
*
* @param int $n The page level you want to check for
* @param int $page_id (optional) The ID of the page to check
*
* @return boolean
*/
function is_nth_level_page($n, $page_id = null) {
global $post;
if (!isset($post) && $page_id == null) {
return false;
} else if ($page_id == null) {
$page_id = $post->ID;
}
$ancestors = get_ancestors($page_id, 'page');
return !empty($ancestors) ? (count($ancestors) == $n - 1) : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.