Title: Help with conditional statement for CSS
Last modified: August 20, 2016

---

# Help with conditional statement for CSS

 *  [adamrobertson](https://wordpress.org/support/users/adamrobertson/)
 * (@adamrobertson)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-statement-for-css/)
 * I want to use a different stylesheet for tag and category pages than the rest
   of the pages on my site. I figure the easiest way to do this would be to put 
   in a conditional statement in the header that says “if a visitor is on a tag 
   or category page, use stylesheet A” and if a visitor is on anything else, use
   stylesheet B.” However, I’m not sure how to do this. Can someone please help?
   Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [adamrobertson](https://wordpress.org/support/users/adamrobertson/)
 * (@adamrobertson)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-statement-for-css/#post-2394340)
 * After some research, I found this:
 * < ?php if (is_tag()) { ?>
    <link rel=”stylesheet” type=”text/css” href=”<?php
   bloginfo(‘template_url’); ?>/style1.css” /> < ?php } else {?> <link rel=”stylesheet”
   type=”text/css” href=”<?php bloginfo(‘template_url’); ?>/style.css” /> < ?php}?
   >
 * Will that do the trick?
 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-statement-for-css/#post-2394348)
 * Put the following in your `functions.php` file:
 *     ```
       function mytheme_enqueue_stylesheet() {
           $mytheme_stylesheet = ( is_tag() ? 'style1' : 'style' );
           $mytheme_stylesheet_url = get_template_directory_uri() . '/' . $mytheme_stylesheet . '.css';
           wp_enqueue_style( 'mytheme_stylesheet', $mytheme_stylesheet_url );
       }
       add_action( 'wp_enqueue_scripts', mytheme_enqueue_stylesheet' );
       ```
   
 * But there are better ways to do this, including taking advantage of the tag-specific
   CSS classes added to the HTML `<body>` tag via `body_class()`.
 *  Thread Starter [adamrobertson](https://wordpress.org/support/users/adamrobertson/)
 * (@adamrobertson)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-statement-for-css/#post-2394369)
 * Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Help with conditional statement for CSS’ is closed to new replies.

 * 3 replies
 * 2 participants
 * Last reply from: [adamrobertson](https://wordpress.org/support/users/adamrobertson/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-statement-for-css/#post-2394369)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
