title: Add multiple categories to body class Wordpress
body: <p>I have found some code which adds the category as a class to the body here: <a href="https://css-tricks.com/snippets/wordpress/add-category-name-body_class/" rel="nofollow noreferrer">https://css-tricks.com/snippets/wordpress/add-category-name-body_class/</a> but it only seems to add one category. Does anyone know how to adjust this code so that it can add multiple category classes to the body?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>add_filter('body_class','add_category_to_single');
  function add_category_to_single($classes, $class) {
    if (is_single() ) {
      global $post;
      foreach((get_the_category($post-&gt;ID)) as $category) {
        // add category slug to the $classes array
        $classes[] = $category-&gt;category_nicename;
      }
    }
    // return the $classes array
    return $classes;
  }</code></pre>
  </div>
  </div>
  </p>