In: , ,
On: 2008 / 03 / 14 Viewed: 20703 times

WordPress 2.5 introduces a neat option: per user Admin Color Scheme. This means that each user can select a stylesheet they like best for the whole admin area. Now onto the fun stuff: adding a per-user selectable custom stylesheet for your blog.

Admin Color Scheme

Concept

The new function behind this feature is wp_admin_css_color(), which is used as following:

PHP:
  1. wp_admin_css_color(
  2.     $shortname, // eg 'mycoolstyle', used to store setting in the wp_options table
  3.     $longname, // eg 'My Cool Style'
  4.     $css_url, // URL to your custom stylesheet
  5.     array(
  6.         $color_code_1, // a HTML color code like '#123456'
  7.         $color_code_2, // or 'red'
  8.         $color_code_3, // or 'rgb(100,100,100)'
  9.         ... // any number of color codes you want
  10.     )
  11. );

This function call populates an array ($_wp_admin_css_colors) which is then used on the profile page to display the cute colorful little table cells. In your plugins, hook the function call into 'admin_init', and you're done.

Example

Say you're a Brazil fan and you want to make a plugin that adds some sunshine into your admin area. You would create a custom stylesheet that would reside into your plugin directory, and the plugin itself would be something like:

PHP:
  1. <?php
  2. /*
  3. Plugin Name: Admin Custom CSS: Brazil!
  4. Plugin URI: http://planetozh.com/blog/
  5. Description: Plugin example: add a per-user custom CSS to the admin area
  6. Author: Ozh
  7. Version: 0.1
  8. Author URI: http://planetozh.com/
  9. */
  10.  
  11. add_action('admin_init','custom_admin_css_brazil');
  12.  
  13. function custom_admin_css_brazil() {
  14.     $plugin_url = get_option( 'siteurl' ) . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__)) ;
  15.     wp_admin_css_color(
  16.         'brazil',
  17.         __('Brazil'),
  18.         $plugin_url . '/wp-admin-brazil.css',
  19.         array(
  20.             '#3c940c',
  21.             '#fffc01',
  22.             '#3005eb',
  23.         )
  24.     );
  25. }
  26. ?>

Real example for the not-so-DIYers : I made this quick plugin and its very quick stylesheet (be warned, the visual result is rather ugly): Plugin Example: Custom Admin CSS.

Braziiiil

Note the cool CSS little trick in the options form :)

Metastuff

This entry "Per User Custom Stylesheet in WordPress 2.5" was posted on 14/03/2008 at 1:37 pm and is tagged with , ,
Watch this discussion : Comments RSS 2.0. You can trackback this post from your own site

30 Blablas

    Pages: « 1 [2] Show All

  1. 21
    WordPress 2.5 ????????????? - WordPress?... United States »
    pingback on 14/Apr/08 at 1:59 am # :

    [...] ????WordPress 2.5 ????????????????????????????????????????????????????????????????????????? WordPress ??????????????????????????????? Fluency???????????????????????????? [...]

  2. 22
    Donncha O Caoimh Ireland »
    wrote, on 15/Apr/08 at 4:28 pm # :

    You know what would be really sick? A random colour generator. It could even change the colour on every page load! :)

  3. 23
    Ozh France »
    wrote, on 15/Apr/08 at 7:52 pm # :

    Donncha O Caoimh » Heh, actually Donncha I'm close to doing this, and guess what, it won't even be ugly. Details some day :)

  4. 24
    Random WordPress 2.5 How-To’s :: W... United States »
    pingback on 16/Apr/08 at 2:07 am # :

    [...] How-to add Per User Custom Stylesheet in WordPress 2.5 by Ozh. [...]

  5. 25
    UtahLuxury.com United States »
    said, on 16/Apr/08 at 5:33 pm # :

    I think it would be cool to have something that pulled data from Adobe Kuler. That way people could just switch styles from there.

  6. 26
    WordPress 2.5 Is Finally Available | Lim... United States »
    pingback on 19/Apr/08 at 2:07 pm # :

    [...] many users, not me though. Not to worry, the old color scheme is an alternative or if you want to set your own colors, Planetozh has a guide as to how you can do just that via a [...]

  7. 27
    Baltic Amber Colour Scheme, controla los... United States »
    pingback on 20/Apr/08 at 11:26 pm # :

    [...] fue uno de los primeros cambios de lo que me enteré se venian con wordpress gracias a Ozh, se trata del Admin Color Scheme, por defecto wordpress sólo cuenta con 2 [...]

  8. 28
    Dalton United States »
    said, on 29/Apr/08 at 8:04 pm # :

    Hey, I did one! It's a super-minimal monochrome version. Thanks for the tip.

  9. 29
    Blog | ?????? ????? ? ?????-?????? ? WP ... Luxembourg »
    pingback on 01/May/08 at 5:51 pm # :

    [...] ????? ?????? ????????? ?? ??? ???? ???? ? ???, ??? ????????? ????? ?????????? ?????? ? ????. ?? ?????? ?????????? ???????? ??????? wp_admin_css_color();. ????? ????????? ????? ?????????? ??????, ? ????? ? ? ??????? ???????. ? ??????? ???????????? ?????????? ????? ???????? ?????. ????? ?????? ? ?????? Per User Custom Stylesheet in WordPress 2.5 [...]

  10. 30
    oyun oyna Sweden »
    said, on 03/May/08 at 9:57 am # :

    the good code, love Wp :)

Pages: « 1 [2] Show All

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.

Read more ?

Close
E-mail It