Skip to content

Instantly share code, notes, and snippets.

@ginocremer
Created March 4, 2014 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ginocremer/9345640 to your computer and use it in GitHub Desktop.
Save ginocremer/9345640 to your computer and use it in GitHub Desktop.
Page Slug in Body Classes WordPress
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