Different Stylesheet For Different WordPress Categories
August 12th, 2008Here’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?
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.
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" />
Change that out to something like this
<?php if (is_home()) { ?>
<link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(’template_url’); ?>/style2.css” />
<?php } else { ?>
<link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(’stylesheet_url’); ?>” />
<?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.
Related Entries
- Tame Those Unruly Sidebar Categories
- Who Moved My Post IDs?
- WordPress 2.6.2 Update Alert
- New Video: Moving Your WordPress Installation
- WordPress Widgets


How To Use Technology To Improve Your Marketing And Productivity
October 26th, 2008 at 9:20 am
Great post, its exactly what im looking for! But how would you do multiple conditions ? As in one for home one for archives, one for pages etc ??
Ive tired the above and it does not work ! Im sure its something simple but i just cant get my head around it.
Thanks for the great post.
October 27th, 2008 at 12:26 pm
Hi Parody. You’ll need to do an if else statement. Like this:
Check out WP’s Conditional Tags page in the Codex. While it does not explain it for style sheets, the concept is the same.
http://codex.wordpress.org/Conditional_Tags