How To Add A Second Style Sheet In Your Theme

In this tutorial, i’ll show you how to create and add a second style.css file in your theme.

You can add the style sheet to your parent theme however its best practice to add it in your child theme.

Add Custom Style Sheet In Child Theme

1. First step is to copy this PHP code from the view raw link and paste it at the end of your child themes functions.php file:

2. Second step is to create a new file named custom.css in your child themes folder.

3. Third & final step is to paste this text at the start of the file.

All your custom CSS code can now be added below the line in your new custom.css file.

Custom Home Page Style Sheet

You can also use a second style sheet to style multiple pages or posts by adding a conditional tag to the code.

If you’re planning on making big changes to one or more pages on your site, which is different to the main style.css file, this is a good option.

You can also use a different conditional tag if using a static page as your home page.

is_front_page()

Blog Page Style Sheet

Another option when using a conditional tag for your custom blog page is to use:

is_page('007')

Simply replace the 007 with the page i.d for your blog page.

Category Archives Style Sheet

This code adds a second style sheet which you can use to style all category archives the same.

You can add the category name or category i.d to the conditional tag to style each archive page differently.

Here’s 2 examples:

is_category('007') or is_category('news')

Differences for Parent Themes Vs Child Themes

According to Chip Bennett, references to ‘stylesheet directory’ should be reserved for child themes. In this case, you can simply change the code above according to your own beliefs.

https://twitter.com/chip_bennett/status/343394686184091648

get_bloginfo( 'stylesheet_directory' ) or get_stylesheet_directory_uri()

Where To Add Second Style Sheet

To create a new style.css file, use a code editor like Notepad++ and save it as a .css file

  • You can place the second style sheet in the main root directory of your child theme which is exactly the same location as the default style.css file. Remove the css/ from the code snippets above if this is your preferred method.
  • You can create a new folder named css and place the file in there. This is the method i have used as evident in the code snippets above.

Adding CSS To Themes & Plugins

Learn more about how to add scripts to your themes and plugins.

The StudioPress Eleven40 child theme contains code like this to add a second style sheet for the home page.

Learn more about how to use the wp_enqueue_style function in WordPress.

Conclusion

As you can see, its simply a matter of using conditional tags to determine which pages are styled with the CSS code you add to your second style.css file.

How About You?

Have you ever used a second style sheet or wanted to but didn’t know how to go about it?

Related Solutions


Comments

23 responses to “How To Add A Second Style Sheet In Your Theme”

  1. […] How To Add A Second Style Sheet In Your Theme […]

  2. […] scripts using best practice includes using the same method as loading style sheets which also include the wp_register and wp_enqueue functions to enqueue a style.css file […]

  3. Gary Powell Avatar
    Gary Powell

    I’m trying to make a custom page inside of genesis framework and style it totally different than the rest of the site. I’m not sure how to do that. I’ve add the scripts from the first three steps to my function.php file and added the file from the “Add Second Style Sheet To Customize Specific Page WordPress.php” to my custom page and it styles the whole site with my custom.css file. I just want the one page styled with the custom.css file. Am I doing something wrong?

  4. This is really great, just what I was looking for thank you!

  5. I’m trying to use this method on a site I’m currently working on that has one look for the main site and a different look for the blog. Unfortunately when I go to the blog the second style sheet is having no effect…any thoughts or help is greatly appreciated.

    1. Brad Dalton Avatar
      Brad Dalton

      Why don’t you add a unique body class to the blog page template.

      1. That’s a good idea, but I’d have to add one to every element of the blog pages (single, archive, etc.) as the blog will be using a different header, different navigation and an entirely different layout. =(

        1. Brad Dalton Avatar
          Brad Dalton

          You could add the body class conditionally and exclude the front page

          Or just add a unique body class to the front-page.php file.

          1. Thanks, I’ll give that a try…was just hoping to get the second style sheet method working as it seemed like it would make things super simple, particularly after getting using your tutorials for changing the layouts.

          2. Brad Dalton Avatar
            Brad Dalton

            I did test this to make sure it works. Not sure why it isn’t for you.

          3. I can see that it loads the second style sheet, but none of the styles are taking effect.

  6. Michael Musgrove Avatar
    Michael Musgrove

    As someone who currently is working on a client’s site that had 5! different stylesheets when given to me, I urge anyone who wants to have separate stylesheets to comment them well to explain why and what exactly is in the extra file(s) for the developers that come after you. This technique can become a real mess in the wrong hands, believe me.

    1. Brad Dalton Avatar
      Brad Dalton

      Good point.

      I don’t see any reason to use more than one file for CSS and one for PHP.

  7. Zach Russell Avatar
    Zach Russell

    This is a very useful article Brad. I just ran into an issue where I want to use SASS to add css rules to an existing theme, and you cannot @import a URL at the bottom of an existing stylesheet and this came to the rescue. Thanks!

    1. Brad Dalton Avatar
      Brad Dalton

      Hi Zach

      I haven’t worked with SASS yet but i did test out this solution and its a good way to use a different style sheet.

      Glad you found it useful and thanks for the comment.

  8. Hi Brad,

    Can you please explain how you got the (updated) in your date in the post info?

    Thanks!

    1. Brad Dalton Avatar
      Brad Dalton

      Hi Lisa

      Yes, I added some PHP code to my functions.php file.https://gist.github.com/braddalton/5787916

      I used forked Greg Rickabys code and modified it so it uses Genesis 2.0 HTML 5 hooks and excludes my portfolio page using a conditional tag.

      If you’re not running HTML 5, you will need to change the hooks or use Greg’s original code which uses the old XHTML hooks https://gist.github.com/gregrickaby/2838395

  9. Mathew Porter Avatar
    Mathew Porter

    i assume you could use this to conditionally load other files if required?

    I can see the reasons why people may want to load select styles in a separate file on particular pages, but if the increase in file size and added http request is more than just having those styles in the first style sheet, then really you should just go for the single.

    1. Brad Dalton Avatar
      Brad Dalton

      Hi Mathew

      Yes, depends on what the files are for.

  10. Keith Davis Avatar
    Keith Davis

    As an aside Brad
    I checked out the Yoast post you mentioned on “Schema.org & Genesis 2.0”

    http://yoast.com/schema-org-genesis-2-0/

    Are you planning to put anything out explaining Schema.org?

    I think Yoast assumes that his readers are familiar with it.

    1. Brad Dalton Avatar
      Brad Dalton

      I might at some stage but was actually trying to stay away from SEO because i think its more opinion than fact. Plus what works now may not work down the track

      If i find something worthwhile relating to schema and Genesis i’ll certainly write about it.

      Have already written a couple of posts about Schema about a year ago.

      Thanks for stopping by Keith.

  11. Keith Davis Avatar
    Keith Davis

    Never used a second stylesheet Brad but it’s nice to know that it can be done and how to do it.
    In a few months time when I do need to use a second stylesheet I’ll be looking high and low for this post.

    1. Brad Dalton Avatar
      Brad Dalton

      Me either Keith.

      I noticed Eleven40 uses one and a client asked me recently about how to add one which is why i wrote the post.

      I know you could also use a custom body class but this is a better way to do it if you want totally different styling for the entire page.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.