5

I have created some custom widgets for my client to use, but I want to make them stand out amidst the fifteen or so standard widgets in the admin area. How can I do this?

I have solved this problem myself and will place the solution here, but please feel free it add a better solution if you have one.

1 Answer 1

8

All widgets in the admin area get an id in the style widget-[global_counter]_[widget_key]-[widget_id], like widget-59_monkeyman_widget_shortcut-5 (installed widget) or widget-11_monkeyman_widget_shortcut-__i__ (an uninstalled widget in the list).

If your widget key contains something unique for all your widgets (like your company name), you can use this and add a substring attribute CSS selector (which works in most browsers). In my case div.widget[id*=_monkeyman_] does the trick, so I add a little CSS snippet in the widgets.php admin page header:

add_action('admin_print_styles-widgets.php', 'monkeyman_widgets_style');
function monkeyman_widgets_style()
{
    echo <<<EOF
<style type="text/css">
div.widget[id*=_monkeyman_] .widget-title {
    color: #2191bf;
}
</style>
EOF;
}

This gives me the following result: Highlighted widgets amongst regular widgets

7
  • @Jan Fabry - Nice! I wasn't familiar with this. Do you know the browsers it does not work with? Commented Oct 18, 2010 at 20:31
  • @Mike: It appears only IE6 doesn't recognize it. Maybe some Javascript can fill that gap, by adding an extra class?
    – Jan Fabry
    Commented Oct 18, 2010 at 20:56
  • @Jan Fabry - Bah! For admin side, IE6 users can just upgrade. :-) Commented Oct 19, 2010 at 3:39
  • @Jan: Keep in mind to not destroy the UI a user expects. Those changes are cool but can have a downside. Only that I have said it :)
    – hakre
    Commented Dec 20, 2010 at 15:17
  • @hakre: I would only do this on sites I created for clients, not in a plugin that others might use. So then the users are already used to whatever weird things I teach them!
    – Jan Fabry
    Commented Dec 20, 2010 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.