Skip to content

Instantly share code, notes, and snippets.

@leoken
Created April 4, 2013 10:03
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/5309227 to your computer and use it in GitHub Desktop.
Save leoken/5309227 to your computer and use it in GitHub Desktop.
adds a class to the top level parent of a page or post
<?php
function top_level_parent_class($classes) {
global $post;
if (is_page() && !$post->post_parent && !is_front_page()) {
$classes[] = 'page-top-parent';
}
return $classes;
}
add_filter('body_class', 'top_level_parent_class');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment