Different CSS style for logged in WordPress users

Update: I wrote a theme switch plugin that changes the template for logged in users. It's available here.

I like to tweak my wordpress theme. And I'm far too lazy to set up a second blog just for development. So I'm looking for a solution to work on my template without distracting visitors. I think one day I'll write an extension that is a little more powerful than this trick, but it's a start.

The easiest case is that you sometimes want to play around with your CSS styles. In this case, just add something like the following example to your template header. Put it where you include your CSS, and only logged in users will see your experimental CSS.

    @import url("<?php
    if ($user_ID) {
        echo bloginfo('template_directory') . "/experimental.css";
    }
    else {
        echo bloginfo('stylesheet_url');
    } ?>");
Of course, you can be more specific than showing any logged in user the testing style. Just compare the $user_ID with some specific ID.

2 comments

  1. avatar
    wrote this comment on

    Your plugin is great, I downloaded and use constantly, and this tip is also very cool, it would be great to have a plugin that already do this for us, but only to make the code really helps, thank you for your efforts in creating the plugin Theme Switch.

  2. avatar
    wrote this comment on

    God bless you.

Reply

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo