• 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

    (@adamrobertson)

    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?

    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

    (@adamrobertson)

    Thanks!

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

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