Skip to content

Instantly share code, notes, and snippets.

@madysondesigns
Created March 21, 2013 23:16
Show Gist options
  • Save madysondesigns/5217699 to your computer and use it in GitHub Desktop.
Save madysondesigns/5217699 to your computer and use it in GitHub Desktop.
WordPress body classes
//print page and parent slugs for css classes
function page_slug_classes($classes) {
global $post;
$classes = array();
//get the slug of any parent pages
$parent_slug = basename(get_permalink($post->post_parent));
array_push($classes, $parent_slug);
//get the slug of the current page
if ( is_page() && $post->post_parent ) {
$page_slug = basename(get_permalink());
array_push($classes, $page_slug);
}
return $classes;
}
add_filter('body_class','page_slug_classes');
@madysondesigns
Copy link
Author

Having this in my functions.php results in no body classes. However, if I call the function directly and use print_r, it prints the array with the correct slugs in it.

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