Stylesheet Chooser Version 0.2

I had tried for a while to find a way to allow users to choose their favorite theme for this website. I decided to do it as a Wordpress plugin, which I offer today for other Wordpress users. Installing it is quite simple: Download, rename to stylesheet_chooser.php, upload it to your wp-contents/plugins directory and activate it from the admin interface.

To define which stylesheets to use (no, it's not automatic...), you have to define an array called $styles, before you call any of the other functions.You can do it like this, for example :
$styles=array("styles/new","styles/default","styles/no-style"); if your stylesheets are in the styles directory. Omit the '.css' part. The first one in the list will be used as your default style. The plugin will automatically selectthe last part of the path (in this case new, default and no-style) and use them as the text in the selection box.

In the plugin file (stylesheet_chooser.php), change the two lines below to use text in your language:

   <span class="warning"><?php _e("Si votre navigateur en &eacute;tait capable, vous pourriez ")?></span>
 <label for="newstyle"><?php e('Change style...')?></label>

In your template (index.php) you have to insert two functions:

style_link() will insert the style sheets link. You have to put it between the <head> and </head> tags in your template.

The optional parameter - for example style_link(false) - can be set to 'true' (default) if you want to @import the style sheets (ignored by NS4), or to 'false' to get this kind of links: <link rel="stylesheet" title="....> for the current chosen style sheet and like this: <link rel="alternate stylesheet" title="....> for the other(s).

style_chooser() will insert the form that is used to select the stylesheet. Place it wherever you want, in your sidebar for example.

In version 0.23+, it is possible to have a short comment appear below the selection dropdown. For this, the only thing you have to do is insert it in your stylesheets like this:

/*
Comment: Write your comment here.
*/

And that's it, now each stylesheet has it's own "introduction text".

Now that you know all this, you can :


28 comments about 'Stylesheet Chooser Version 0.2'

Get the comments feed for this entry or post a trackback from your own blog

  1. 4 years, 2 months ago,

    [...] r slvShowNewIndicator(1094170038); Filed under: WordPress Plugins|Google it! This Wordpress plugin allows users to change stylesheets. [...]

  2. Gravatar
    Frank said:
    4 years, 2 months ago,

    The style chooser only works when you have cookies enabled. I always have cookies disabled in Firefox, with exceptions for a couple of sites. I don't know if there is a workaround possible so this works without the use of cookies, but that might be preferable to this solution if it works in all situations.

  3. Gravatar
    André said:
    4 years, 2 months ago,

    Dear Jonathan, why does the plugin created this stylesheet-tag at the end <link rel="alternate stylesheet"type="text/css" media="screen" title="" href="http://www.jfoucher.marinetechs.com/css"

  4. Gravatar
    Jonathan said:
    4 years, 2 months ago,

    It is possible to use sessions instead of cookies, but I have trouble understanding their behaviour. I will try to find a way, though. Keep in touch if you're interested in the cookie-free version.

  5. Gravatar
    Jonathan said:
    4 years, 2 months ago,

    That was a little bug, thanks for pointing it out.

    It's fixed in the new version.

  6. Gravatar
    Nik said:
    4 years, 2 months ago,

    show_chooser() ?? When you've got style_link(), it'd be more understandable to choose style_chooser() as function name. Makes it more easy to see what functions come from what plugin

  7. Gravatar
    Jonathan said:
    4 years, 2 months ago,

    Done!

  8. Gravatar
    Michiel said:
    4 years, 2 months ago,

    Hi, the download does not work, it is redirected to http://www.jfoucher.marinetechs.com/2004/09/02/stylesheet-chooser/

  9. Gravatar
    Jonathan said:
    4 years, 2 months ago,

    It should be fixed now. Let me know if you still have problems, ok ?

  10. Gravatar
    Jonathan said:
    4 years, 2 months ago,

    Sorry to all the recents commenters. I had some database problems and lost some of the newest comments. I even lost one post that wasn't backed up, but got it back from Google's cached version. Thanks !

    Thanks to Francesco too, for correcting that bug.

  11. 4 years, 2 months ago,

    Hi!

    I have a problem with this plugin. It displays the default stylesheet but I'm not able to change the stylesheet to another. It just gives me a 404 error page, what's wrong?

  12. 4 years, 2 months ago,

    And it doesn't insert the alternative stylesheet links (

  13. Gravatar
    francesco said:
    4 years, 2 months ago,

    same problem here.

  14. Gravatar
    francesco said:
    4 years, 2 months ago,

    i've fixed it this way: around line 156 in the plugin you find the form. action is srt to "/", replace it with "< ?php echo $_SERVER["REQUEST_URI"]; ?>"

  15. Gravatar
    Jonathan said:
    4 years, 2 months ago,

    Yes! of course!

    Francesco, a big thank you to you!

  16. 4 years, 2 months ago,

    Whippee!

    Thank you, Jonathan, for this great plugin and thank you, Francesco, for this great fix!

  17. Gravatar
    Jonathan said:
    4 years, 2 months ago,

    Ok, I managed to restore the comments from the notifications I received by email, but I don't know if you were subscribed to comments. If you were, you aren't anymore, I didn't want to force this on anybody...

  18. Gravatar
    francesco said:
    4 years, 2 months ago,

    now i have another small problem: i have to change style twice in order to see it applied. the weird thing is that on my server at home i just need to switch once, while on my provider's one i have to do it twice. Maybe an issue with different versions of php? i haven't had the time to check the code again to see if i can fix this. anyone else had the same problem?

  19. Gravatar
    Jonathan said:
    4 years, 1 month ago,

    In fact, using $_SERVER['REQUEST_URI'] didn't work at all for me, so I used get_bloginfo('url'), which gives the correct url in all cases.

  20. 4 years, 1 month ago,

    Hello,

    I'm not very familiar with WordPress or PHP. Where do I have to create the array you mention? ($styles=array("styles/new","styles/default","styles/no-style")) Could you please elaborate a little on this?

    Merci beaucoup,

    Erwin

  21. Gravatar
    Jonathan said:
    4 years, 1 month ago,

    Anywhere above the style_link() function call is fine.

    If you have to css file named wp-layout.css and wp-layout2.css in the same directory as your index.php file, the array definition would look like this :

     $styles=array("wp-layout","wp-layout2");
    

    Hope this helps.

  22. 4 years ago,

    [...] changes… this may or may not happen, but it’s pretty cool to think about, eh? Jonathan Foucher - Salamba ? Stylesheet Chooser Version 0.2 --> --> [...]

  23. 4 years ago,

    [...] As a self-prescribed stress-relieving treatment, I have installed Jonathan Foucher’s style sheet chooser plugin for WordPress, so now you can choose your favorite style to look a [...]

  24. Gravatar
    Margaret said:
    4 years ago,

    I'm getting the following error:

    Fatal error: Call to undefined function: lp() in /home/margaret/public_html/wp-content/plugins/stylesheet_chooser.php on line 184

    You can see it in action. I, too, am not versed in php, so I'm just sort of muddling my way through.

  25. 4 years ago,

    Nifty new styleswitcher As a self-prescribed stress-relieving treatment, I have installed Jonathan Foucher's style sheet chooser plugin for WordPress, so now you can choose your favorite style to look at the page. The new style is called "Whistler" because it's based on ...

  26. Gravatar
    Jonathan said:
    4 years ago,

    Yeah, sorry about that, my mistake. Should be solved now if you download it again. But I see you got your problem solved. Nice looking alternative style, BTW.

  27. Gravatar
    Joseph said:
    3 years, 11 months ago,

    I have a problem similar to the one Antti Leväsaari experienced:

    1. I put the stylesheet_chooser.php file in my wp-content/plugins directory and it is Activated on my WordPress Plugins page.
    2. my stylesheets are in the /styles folder (they are named no-style.css, default.css and new.css).
    3. I INSERT style_link(false) between the Head tags of my Index.php page.
    4. I INSERT style_chooser() in the Body of my page.

    Yet the website shows all three CSS styles but only loads the one listed first. Have I missed a step?

    here's the example... http://www.strangeisle.com/

    Thank you.

  28. 3 years, 10 months ago,

    [...] 220;Simple Sky,” though I’m working on some changes. Jonathan Foucher’s “Style Sheet Chooser” lets users choose the css they prefer. So here&#82 [...]