Skip to content

Instantly share code, notes, and snippets.

@ryanve
Created December 27, 2015 23:40
Show Gist options
  • Save ryanve/3a6b6480993af3de492d to your computer and use it in GitHub Desktop.
Save ryanve/3a6b6480993af3de492d to your computer and use it in GitHub Desktop.
wordpress check if is page or subpage of that page
<?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;
};
@ryanve
Copy link
Author

ryanve commented Dec 27, 2015

$is_page('events') matches /events/**

@ryanve
Copy link
Author

ryanve commented Dec 27, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment