Different Stylesheet For Different WordPress Categories

Here’s an interesting question I found on Twitter today. Here’s what she asked.

Anyone know how you over write they style sheets for one page on a WordPress blog?

hexcodessm
Photo credit: Diego Sinning

I’m not sure if she’s referring to Pages in WordPress or categories. In both cases it is possible but you have to be prepared to write a small php command. Here’s where knowing just a little bit of basic PHP can go a long way when working with WordPress.

There are several methods of doing this but we’ll only cover one here to keep things simple. Let’s say we want a special style sheet just for the home page. This is what you’d put in your header.php of your theme. Find the line of code that references the style sheet. It would look something like this.


Change that out to something like this

< ?php if (is_home()) { ?> 

< ?php } else {?>

 < ?php } ?>

Make sure you enter the correct name for the alternate style sheet. In this case, I’ve named my alternate style sheet style2.css

You can also specify a different style sheet for different categories, authors, specific Pages or single post page by using different conditional tags as explained in the Codex.

Example if you want the style2.css for category 2 archive page, just switch out is_home() for is_category(‘2’) where the number 2 is the category ID.

Scroll to Top