Anyway to edit the titlebar of WordPress Widgets in the Admin area?

I believe you are looking for $params = apply_filters( 'dynamic_sidebar_params', $params );
(look here: https://github.com/WordPress/WordPress/blob/master/wp-includes/widgets.php#L706).

Now this filter will evaluate both in front end and back end. so to answer your question, you could wrap your filter in a if( is_admin() ){ // Do icons } check.

Better yet, you could define this at registration level with your register_sidebar( $args ) function. Check out Line 236 for the definition of the function and Line 250 for the actual argument you would need to customize conditionnaly. Something like this

$before_title = is_admin() ? '<span class="custom-icon"></span><h2 class="widgettitle">' : '<h2 class="widgettitle">';

$args = array(
  // ... your custom args definition
  'before_title' => $before_title,
);

register_sidebar( $args );

UPDATE

After digging deeper into code, my answer doesn’t fit your need because of a few things.

  • Widget titles are being HTML escaped, so no tag can be rendered
  • A filter exists widget_title to override HTML escape behaviour, but it is not applied for the admin area, therefore we cannot modify this behaviour for your use case since it’s already ecaped when printed on Line 229
  • So the only solution possible here is to revert back to jQuery/CSS to apply your desired glyphs

Leave a Comment