Add custom classes to array of body classes.
<?php
/**
* Add custom classes to array of body classes.
*/
add_filter('body_class', function($classes) {
if (!is_singular() && !is_404()) {
$classes[] = 'hfeed';
}
if (is_page() && !is_front_page()) {
$page_slug = get_post_field('post_name', get_the_ID());
if (!in_array($page_slug, $classes)) {
$classes[] = get_post_type().'-'.$page_slug;
}
if ($parents = get_post_ancestors(get_the_ID())) {
foreach ($parents as $parent) {
if ($page = get_post($parent)) {
$classes[] = "parent-{$page->post_type}-{$page->post_name}";
}
}
}
}
return $classes;
});
?>
functions.php