Created
March 21, 2013 23:16
-
-
Save madysondesigns/5217699 to your computer and use it in GitHub Desktop.
WordPress body classes
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
//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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.