Created
March 4, 2014 12:28
-
-
Save ginocremer/9345640 to your computer and use it in GitHub Desktop.
Page Slug in Body Classes WordPress
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
add_filter('body_class','body_class_section'); | |
function body_class_section($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']; | |
} | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment