SHARE
TWEET

Add Categories as CSS Classes

brooklyndesignstudio Jun 30th, 2020 950 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***************************************************************************************
  2. ************************ [ ADD CATEGORIES AS CSS CLASSES ] ***************************/
  3.  
  4. function add_category_name($classes = '') {
  5.    if(is_single()) {
  6.       $category = get_the_category();
  7.       $classes[] = 'category-'.$category[0]->slug;
  8.    }
  9.    return $classes;
  10. }
  11. add_filter('body_class','add_category_name');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top