Created
December 27, 2015 23:40
-
-
Save ryanve/3a6b6480993af3de492d to your computer and use it in GitHub Desktop.
wordpress check if is page or subpage of that page
This file contains hidden or 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
<?php | |
$is_page = function($pages) { | |
global $post; | |
if (!is_page()) return false; | |
if (is_page($pages)) return true; | |
if (empty($post->post_parent)) return false; | |
$parent = get_post($post->post_parent); | |
if (!$parent || empty($parent->post_name)) return false; | |
$slug = $parent->post_name; | |
foreach ((array) $pages as $page) if ($slug === $page) return true; | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$is_page('events')
matches/events/**