Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

Reply To: Change header background for category or pages

Home Forums Support Change header background for category or pages Reply To: Change header background for category or pages

Home Forums Support Change header background for category or pages Reply To: Change header background for category or pages

#108374
Tom
Lead Developer
Lead Developer

Shouldn’t have to insert anything into index.php..

This is the code you want to add into your child theme functions.php:

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->ID)) as $category) {
			echo $category->cat_name . ' ';
			// add category slug to the $classes array
			$classes[] = 'category-'.$category->slug;
		}
	}
	// return the $classes array
	return $classes;
}

Then your CSS should work 🙂