Different CSS style for logged in WordPress users

Tagged WordPress

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.

1
2
3
4
5
6
7
8
9
<style type="text/css" media="screen">
    @import url("<?php
    if ($user_ID) {
        echo bloginfo('template_directory') . "/experimental.css";
    }
    else {
        echo bloginfo('stylesheet_url');
    } ?>");
</style>

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.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. Change Typo3 template depending on column content
  2. Creating a valid WordPress theme
  3. wp_enqueue_style, versioning and conditional CSS comments

2 Comments

  • Posted by Myst on 27. September 2009 at 06:55.

    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.

  • Posted by Ann on 15. December 2009 at 21:34.

    God bless you.

Leave a Reply

Your email is never shared. Required fields are marked *

*
*