I want to add a class name to my custom dashboard widget but I've found no way to do this searching the codex. Right now the only class name on my widget is postbox (which is added in '/wp-admin/includes/template.php') but I would like to add more. How can I do this?

add_action('wp_dashboard_setup', function () {


function widget_2($post){
    var_dump($post); /* string '' (length=0) */
    <div id="graph-points-by-time" class="graph-points-by-time"></div>
    <br class="clear">
    <div id="graph-legend" class="graph-legend height-auto"></div>

You could use postbox_classes filter as follow:

add_filter( 'postbox_classes_dashboard_widget2', function ( $classes ) {

   // $classes is an array; add your custom classes to the array
   $classes[] = 'my-class';

   return $classes;

} );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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