• I’m looking to customize my WordPress dashboard by adding custom widgets using the functions.php file. I have already added some widgets to the dashboard but would like to add some to the right side rather than the left and I’m not sure how to do so (the WordPress help pages aren’t clear enough for me). I would also like to possibly incorporate an image within the widget, if possible. Any help would be greatly appreciated.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The pages are not clear because you’re not supposed to be able to. There’s a white list of widgets that can go there inside of the wp_add_dashboard_widget() declaration. I believe a workaround is possible, though I’ve not tried it. Dashboard widgets are essentially meta boxes, just a special type. You should be able to add your widget to the right by calling add_meta_box() with the correct parameters.

    You still hook “wp_dashboard_setup” action like when you’ve added your other widgets, except you call add_meta_box() instead of wp_add_dashboard_widget(). This is assuming your widget does not have controls. If you do, it’d be best to clone the widget function and add your widget to the white list.

    For the parameters to add your widget as a meta box, most are the same as with wp_add_dashboard_widget(). The ID, name/title, and callback are the same. For the screen, pass the object returned from WP_Screen::get('dashboard'). For context pass 'side'. For priority pass 'core'. For callback args pass array( '__widget_basename' => $widget_name ) where $widget_name is the same as the name/title parameter.

    Like I alluded to earlier, untested. Good luck!

Viewing 1 replies (of 1 total)
  • The topic ‘Creating Custom Widget for Dashboard’ is closed to new replies.