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?
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.
Do You Want A Hands-Free Business?
Then get this guide to help you systemize your business so you'll have more time working on your business.
Hey! I want to make sure you know what you're getting here. In addition to the guide, you will also receive our memo that includes special offers, announcements and of course actionable information.
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.
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.
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
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
Lynette !! your champion!
Thank you so much ! I’m using it now on my site.
Lynette !! your champion!
Thank you so much ! I’m using it now on my site.
Hello again Parody, you’re most welcome.
Hello again Parody, you’re most welcome.