• .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
Wix.com
Jul
15

Integrating Alternative Stylesheets in WordPress Themes

I am sure that everyone has come across WordPress themes which use alternative stylesheets (CSS) to switch between different sets of style information. For example, you can have a look at the following themes that have this functionality :-

Here is how these themes do it :-

Default Stylesheet

Ideally, every WordPress theme has a style.css file associated with it that contains all the style information for the theme. This default stylesheet is usually called in the header.php file of your WordPress theme by something like this :-

Rel=”stylesheet” is what defines the active stylesheet as the default one.

Alternative Stylesheets

Now you will need alternative stylesheets that change the look or the layout of your theme. For example, you can change the color of the background, fonts, positioning of the sidebar, header images etc. To define the alternate stylesheets, you should use something like rel=”alternate stylesheet” during the stylesheet call. Here are some examples :-

You can make new stylesheet files called orange.css and blue.css files and maybe change the background colors for the body of your theme (for this example). Use something like :-

body {background-color:#FF6E1F;}

Goes in orange.css for orange background color

body {background-color:#2C85EF;}

Goes in blue.css for blue background color

Now, place these files in your theme folder (same path as your style.css).

Style Switcher

The styles in the above alternate stylesheets will be included into your theme but will not be used until it is specified in some way. To do this, we can take help of Javascript code which will serve as a style switcher. You can download the Javascript file here :-

Download styleswitcher.js

Please the styleswitcher.js file into your theme folder and include it into your theme by placing the following code above the tag in your header.php file :-

Now, you need a control scheme that will allow you to switch between the alternative stylesheets. Place the following code anywhere in your theme body :-

Orange
Blue

The above code will make new hyperlinks in your theme called Orange and Blue. When you click on these links, your theme’s background color will change to the specified color.

Conclusion

So you can now experiment and tweak different things in your theme using the alternate stylesheets. You can make any number of such stylesheets but make sure that you call them through the Javascript code. I hope you benefit from this article :)

This post was viewed 29,418 times

31 Comments to “Integrating Alternative Stylesheets in WordPress Themes” | Leave a Comment!

  1. I would definitely try this. I have just created a fresh blog using wordpress and I am looking out for some new styles and themes. I liked your tutorial and I will give it a shot. Keep up the good job, and keep sharing more tips and advice on Word Press.

  2. Thavi says:

    It loads the default style sheet for a fraction of second every time I change the page before loading the selected alternate style

  3. Brooke says:

    I spent 6 hours searching and tweaking and thanks to your tutorial i finally got it to work! The only thing though is I cannot get the default style sheet to stick around. It shows up for a few seconds than automatically changes to one of the other styles. This is how I am calling it:

    You can see the site at yobeat.server288.com

    If you have any suggestions for fixing this, i would be greatly appreciative! Thanks for the great tutorial.

  4. Robert says:

    Great tutorial. I am working on a theme now that needs an additional style sheet

  5. webdesign says:

    I studied the css tutorial and I really learned a lot. I think my next homepage will be a lot better than my first one.

  6. speeds says:

    ???—????
    think you?

  7. sunn says:

    Well done!
    Can you make it change automatically on the first day of every season too?

  8. what is this! are you kiddin me!

  9. brion says:

    just brilliant, thanks

  10. Blay says:

    Thanks for this. Question though, I want to make it automatically switch everytime so one comes to the page. I have 4 different pictures in the header with colour changes in the text. I have done everything you said. Its just how would I go to rotate the css /headers automatically instead of clicking on a button?

    • Jai says:

      To do the change automatically, you will have to use some PHP code to randomize it whenever someone visits your page. I hope this code can give you some idea :-


      < ?php
      $random = rand(1,3);
      if($random == 1) {
      // Include your css
      }
      elseif($random == 2) {
      // Include your css
      }
      elseif($random == 3) {
      // Include your css
      }
      ?>

  11. ???? ??? says:

    I think this is a very good post, I will come to this website again

  12. Ness says:

    If you’re talking to me, it’s wp, but the same can also be done quite simply with Joomla, I guess !

  13. Yang says:

    it’s a joomla’ image or wp’s?

  14. Ness says:

    Hi ! Actually, I managed to do it, and it works really fine. I used a js file to get the user’s computer time and to return a stylesheet accordingly. The user can also choose to keep a specific stylesheet (I used cookies), and to toss the cookie to return to the night / day alternance.
    Also, for people who don’t have js enabled, I did a php function which does basically the same, but based on the server’s time.
    Quite a mess mixing both languages, but now it works ^^ I might put the website url here if somebody’s interested (for the moment, the website is still in development).

  15. Richard says:

    I’ve seen this idea before a few times, usually incorporatd with a cookie that allows you to set a style sheet and when you revisit the site it picks up the cookie data and keeps your selection from last time. Nice touch … if you think you can do it?

  16. Ness says:

    Thanks for this !
    I have a question, though : I noticed that even when I don’t choose a specific stylesheet, the cookie “style” is created. I’d like to avoid that (I’m trying to design a two-mode style switcher : as long as the user hasn’t choosen a style, styles are random), but I’m not that much into javascript and I don’t know how to have the cookie created ONLY if the user has chosen a stylesheet.
    Any advise ?

  17. Sauron says:

    I think this is a very good post, I will come to this website again…no doubt.

  18. roro44.com says:

    Really your words are fantastic thanx
    http://www.roro44.com

  19. roro44.com says:

    Really your words are fantastic thanx

  20. spirit says:

    ^_^ I am a Chinese student~

  21. Jason says:

    Thank you for this Jai! It has really helped me a lot.

  22. KrAzy Che3To says:

    I liked this implemented in the templates so I have been working on one for my site.

  23. Very interesting article, and something that I’ve been curious to learn about recently!

    One question I would have is: how useful has the community here found alternating stylesheets to be? Do your readers prefer them, or are they more of a novelty?

    Nice instructional post!

  24. adi says:

    now i know how to change the wp style.
    u’re a good tutor, jai. good job

  25. now i think , i can develop my own wp theme,

    thanks brother for this css tutorial

  26. noobatron says:

    I have been looking for this, since a while but did not know what to search for!

    Thanks, I think I have found it:D

  27. danielchew says:

    I must say that this stylesheet tutorial has helped me a lot in understanding css. Thanks for making this tutorial


Websites that Link to this Post

  1. ?WordPress?????????? | BitGet
  2. ?WordPress?????????? | ???(?)???
  3. Richard Hamilton's Photography Blog » Alternate Style Sheets in WordPress
  4. WordPress : Compresser et changer le fichier CSS par défaut | (Choose Life, Or Die.) | DaPo
  5. ?Wordpress?????????? | ????????|???|????|????|Wordpress|????
  6. you asked for it | ihumanable
  7. ????! » ?Wordpress?????CSS??
  8. WordPress ?i scheme, nu teme | CNET.ro
  9. ??? » ?Wordpress??????????
  10. ???Wordpress?????????? | ???
  11. ?WordPress???????css?? | ??

Leave a comment

Search :
Browse :
Archive :

$$$ Make Money $$$

Become an Affiliate

Welcome to Blog Oh! Blog's affiliate program! I personally invite you to make money by selling all of Blog Oh! Blog's Premium themes.

You will get a whopping 25% share on each sale generated through your affiliate link.

All you need to do is sign up as Blog Oh! Blog's affiliate, choose a banner, paste it on your website or blog and wait for sales to happen. It's as simple as that!

All affiliates will be paid on 10th of every month. Your affiliate earning needs to be a minimum $50 to get paid for each month.

Here is the sign up link and here are some banners to get you started!