treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress - Linking two different style sheet

  • Hi
    Does anybody can tell me how do I link in Wordpress to two different pages to different style sheet.I would like to have different layout in home page but rest of the pages would remain and have defaults styles.css.Where do I place link that link up external sheet for it? Wordpress is using same styles everywhere .Any help or suggestions here please?
    Thnax
  • 1. Find the id number of the page you want the special stylesheet to go to.

    2. Open up header.php and find where your stylesheet is being linked from.

    Change:
    <link rel=\"stylesheet\" type=\"text/css\" href=\"<?php bloginfo('stylesheet_url'); ?>\" media=\"screen\" />


    To:
    <?php if ( is_page(id#) ) {
    echo '<link rel=\"stylesheet\" type=\"text/css\" href=\"<?php bloginfo('template_directory'); ?>/your-special-file.css\" media=\"screen\" />';
    }
    else {
    echo '<link rel=\"stylesheet\" type=\"text/css\" href=\"<?php bloginfo('stylesheet_url'); ?>\" media=\"screen\" />';
    }
    endif ?>


    I'm not a PHP guru, but that should work.
  • Well is not working :-( ... any ides on this one?
  • "markito" said:
    Well is not working :-( ... any ides on this one?

    Just to make sure my PHP is wrong and nothing else, did you replace "id#" with your home page's id?
  • Silly me, I see the problem here!

    Give this one a go:

    <?php if ( is_page(id) ) {
    echo '<link rel=\"stylesheet\" type=\"text/css\" href=\"' . bloginfo('template_directory') . '/your-special-file.css\" media=\"screen\" />';
    }
    else {
    echo '<link rel=\"stylesheet\" type=\"text/css\" href=\"' . bloginfo('stylesheet_url') . 'media=\"screen\" />';
    }
    endif ?>
  • 	<?php while (have_posts()) : the_post(); ?>
    <?php if (is_paged()) : ?>
    <?php $postclass = ('post'); ?>
    <?php else : ?>
    <?php $postclass = ($post == $posts[0]) ? 'featured-post' : 'post'; ?>
    <?php endif; ?>

    <div class=\"<?php echo $postclass ?>\">


    sorry i didn't explain myself.

    this works really well.
  • I don't think you understand what the OP is asking for.

    Here's another one, from Chris' book Digging into WordPress.

    Conditionally loading extra CSS files
    <?php if (is_page_template(\"page-snippet.php\")){ ?>
    <link rel=\"stylesheet\" type=\"text/css\"
    href=\"<?php bloginfo('stylesheet_directory'); ?>/css/snippets.css\" />
    <?php } ?>
  • Since you want it to act on the homepage you should replace is_page_template("page-snippet.php") with is_front_page().
  • "davesgonebananas" said:
    Since you want it to act on the homepage you should replace is_page_template("page-snippet.php") with is_front_page().

    Yes, sorry, forgot to update that. Too quick with my copy and paste!

    Should also mention that when using that method, it means you'll have two stylesheets being loaded at the same time.