Body class (wordpress)

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()) {
    if (!in_array(basename(get_permalink()), $classes)) {
      $classes[] = get_post_type().'-'.basename(get_permalink());
    }
    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

< toolbox