Skip to content

Instantly share code, notes, and snippets.

@donaldallen
Created December 20, 2013 15:36
Show Gist options
  • Save donaldallen/8056458 to your computer and use it in GitHub Desktop.
Save donaldallen/8056458 to your computer and use it in GitHub Desktop.
Add the current page slug to your body class. Very handy!
<?php
add_filter('body_class', function($classes) {
global $wpdb, $post;
if (is_page()) {
if ($post->post_parent) {
$parent = end(get_post_ancestors($current_page_id));
} else {
$parent = $post->ID;
}
$post_data = get_post($parent, ARRAY_A);
$classes[] = 'parent-' . $post_data['post_name'];
$classes[] = $post->post_name;
}
return $classes;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment