Created
December 20, 2013 15:36
-
-
Save donaldallen/8056458 to your computer and use it in GitHub Desktop.
Add the current page slug to your body class. Very handy!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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