Add body css class name by template tag

PHP
// 加入 body class 名稱
function add_slug_to_body_class($classes) {
  global $post;
  if (is_front_page()) {
    $key = array_search('blog', $classes);
    if ($key > -1) {
      unset($classes[$key]);
    }
  } elseif (is_page()) {
    $classes[] = sanitize_html_class($post->post_name);     // 確保只會有英數當 class
  } elseif (is_singular()) {
    $classes[] = sanitize_html_class($post->post_name);
  }
  return $classes;
}
add_filter('body_class', 'add_slug_to_body_class');