Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoken/5309172 to your computer and use it in GitHub Desktop.
Save leoken/5309172 to your computer and use it in GitHub Desktop.
Adds a Grand Parent class to the body
<?php
function get_grandparent($page_id) {
$current_page = get_page($page_id);
if ($current_page->post_parent > 0) {
$parent_page = get_page($current_page->post_parent);
if ($parent_page->post_parent > 0) {
return $parent_page->post_parent;
} else {
return false;
}
}
return false;
}
function grandparent_id_class($classes) {
global $post;
if (is_page() && $post->post_parent && !is_front_page() && get_grandparent($post->ID)) {
$grandparent = get_grandparent($post->ID);
$classes[] = 'grandparent-pageid-'. $grandparent .'';
}
return $classes;
}
add_filter('body_class', 'grandparent_id_class');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment