How To: Using Another Stylesheet For Certain Pages
June 7, 2008 by Tony | Tag(s): WordPress Code, WordPress Hacks, WordPress How-To
When you think of having two stylesheets for a website or blog, you typically think of an alternate stylesheet specifically for a web browser, such as an Internet Explorer stylesheet.
One thing we haven’t covered yet is how to add a second stylesheet that is only used for certain pages. In order to do this, you’ll want to open up your header.php file and locate your existing stylesheet. The stylesheet code should look something like this:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
Now, we need to make an adjustment so that it will only show the code in a certain situation. For example, if you want a certain category to use a different stylesheet, you’d use the following code:
<?php if ( is_category('1') ) {
<link rel=”stylesheet” href=”<?php bloginfo(’template_url’); ?>/cat-1.css”
type=”text/css” media=”screen” />;
<?php } else { ?>
<link rel=”stylesheet” href=”<?php bloginfo(’stylesheet_url’); ?>”
type=”text/css” media=”screen” />
<?php } ?>
In this example, we are assigning the cat-1.css to be used for category 1. Every other page will use the normal stylesheet.
You can plugin in alternate information as needed.
Related WordPress Posts
- How To: Display A WordPress Tag Cloud On Your Blog (0)
- WordPress Hack: Creating a Two-Tiered Navigation Menu (0)
- How To: Alternating Your Post Background Colors (0)
- How To: Hiding Your Sub-Categories in WordPress (0)
- How To: Display the Recent Posts of Specific Categories (0)
- How To: Adding Comment Numbers To Your WordPress Theme (0)

![Subscribe to [Blog Tutorials]](http://blogtut.com/wp-content/themes/BlogTutorialPro/images/rss.gif)
![[del.icio.us]](http://blogtut.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://blogtut.com/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://blogtut.com/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://blogtut.com/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://blogtut.com/wp-content/plugins/bookmarkify/myspace.png)
![[Newsvine]](http://blogtut.com/wp-content/plugins/bookmarkify/newsvine.png)
![[Reddit]](http://blogtut.com/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://blogtut.com/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://blogtut.com/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://blogtut.com/wp-content/plugins/bookmarkify/technorati.png)
![[Windows Live]](http://blogtut.com/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://blogtut.com/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://blogtut.com/wp-content/plugins/bookmarkify/email.png)






Comments
Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!