Created
September 1, 2016 13:54
Star
You must be signed in to star a gist
For creating conditional based logic for page or any children pages that are under a parent page.
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 if_page_or_ancestor_page_is($page_slug = NULL) | |
{ | |
$is_page = false; | |
if (is_page()) { | |
global $post; | |
/* Get an array of Ancestors and Parents if they exist */ | |
$parents = get_post_ancestors($post->ID); | |
$all_pages = array_reverse(array_merge($parents, array($post->ID))); | |
foreach ($all_pages as $page_id) { | |
$page = get_page($page_id); | |
if ($page->post_name == $page_slug) { | |
$is_page = true; | |
} | |
} | |
} | |
return $is_page; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment