• 1.
    add_filter('body_class', 'tax_body_class');
  • 2.
    // add category nicenames in body class
  • 3.
    function tax_body_class( $classes ) {
  • 4.
    	
  • 5.
    	if ( is_singular('post') || is_category() ) {
  • 6.
    	
  • 7.
    	global $post;
  • 8.
    	
  • 9.
    	$terms = get_the_terms( $post->ID, 'category' );
  • 10.
    	
  • 11.
    		if ( $terms && ! is_wp_error( $terms ) ) {
  • 12.
    		
  • 13.
    			foreach ( $terms as $term ) {
  • 14.
    				
  • 15.
    				// assign body class for the blog categories
  • 16.
    	
  • 17.
    		    			$classes[] =$term->slug;
  • 18.
    		    		
  • 19.
    	
  • 20.
    			}
  • 21.
    		}
  • 22.
    	
  • 23.
    	} 
  • 24.
    	
  • 25.
    	return $classes;
  • 26.
    	
  • 27.
    }
add_filter('body_class', 'tax_body_class'); // add category nicenames in body class function tax_body_class( $classes ) { if ( is_singular('post') || is_category() ) { global $post; $terms = get_the_terms( $post->ID, 'category' ); if ( $terms && ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { // assign body class for the blog categories $classes[] =$term->slug; } } } return $classes; }

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter