Created
January 31, 2013 17:16
-
-
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');
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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