Skip to content

Instantly share code, notes, and snippets.

@JodiWarren
Created January 31, 2013 17:16
Show Gist options
  • Save JodiWarren/4684483 to your computer and use it in GitHub Desktop.
Save JodiWarren/4684483 to your computer and use it in GitHub Desktop.
Function to return true if the current page matches or is a child of a given slug. Call it like is_page_or_child('about');
function get_ID_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}
}
function is_page_or_child($slug){
$ispage_ID = get_ID_by_slug($slug);
if (is_page($ispage_ID) || in_array($ispage_ID, get_ancestors(get_the_ID(), 'page')) ) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment