• Resolved Matt Hancock

    (@matthancocknz)


    At the moment, I have 2 separate stylesheets that I’m using for a website.

    One of the standard style.css and another is homepage.css which is being used just for the ‘Home’ page instead WP.

    So I’m using the two pieces of code to call them:

    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" />
    <?php if (is_page('Home')) { ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/homepage.css" type="text/css">
    <?php }; ?>

    Naturually, this is causing some clashes with the 2 stylesheets and I also think it looks a tad messy.

    Is it possible to write a statement that will only use homepage.css for ‘Home’ and style.css for the rest of the website?

    Cheers. ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Chip Bennett

    (@chipbennett)

    Sure (using your code above):

    if ( ! is_home() ) { ?>
         <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" />
    <?php } else { ?>
         <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/homepage.css" type="text/css">
    <?php }

    Alternately:

    1) Load style.css always, and use the body.home class to change styles as necessary

    2) Create a “home.php” template file, in which you link homepage.css, rather than style.css

    Thread Starter Matt Hancock

    (@matthancocknz)

    Chip,

    Thanks for the assistance. I tried the code snippet you provided and had limited success.

    At the moment, I have a template file called homepage.php which is assigned to ‘Home’ in WP. How would I achieve something along the lines of your second suggestion?

    Ideally, I would like to avoid having style.css and homepage.css loaded at the same time.

    Thanks again. ??

    Chip Bennett

    (@chipbennett)

    Try renaming “homepage.php” to “home.php” if it is being used as a blog posts index on the front page.

    Or, if you are using a Static Page on the Front Page, try renaming “homepage.php” to “front-page.php”.

    Then, in this template file (whether “home.php” or “front-page.php”), omit the link to style.css, and only include the link to homepage.css.

    Thread Starter Matt Hancock

    (@matthancocknz)

    Chip,

    Thanks again.

    I did some more scouring around and my problems were related to the recent admin bar addition in 3.1. Once I disabled it, everything worked out.

    Still, it’s really interesting to know and to implement.

    Thanks for your help. ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using PHP IF statement to change stylesheets’ is closed to new replies.