Hide widgets from WordPress dashboard

Cleanup WP dashboard

Cleanup WP dashboard

A lot of WordPress plugins adds widgets to WordPress administrator dashboard automatically. Some time you may wish to hide selected widget, – may be it is not interested for you, or may be it even does not contain a bit of useful information.

Some of plugins were written with user friendly policy in a mind and has an option at their settings to hide selected widget. What to do with plugin which does not allow blog owner to manage what widget to show at the WordPress back-end dashboard and what does not?

Yes, any user may hide unneeded widget switching of correspondent checkbox inside the “Screen Options” at the top of the page. But suppose, that You, as administrator, wish to make your blog dashboard more user friendly and to help your users to spend their time more effectively. Some times you even do not wish to let user know, that some widget is available at all. Use this recipe to make your dashboard cleaner.
Let use as an example the widgets from “WooCommerce – Commissions King” plugin from Visser Labs. Look at the picture below:

WooCommerce - Commission Kings plugin widgets

Dashboard widgets from Visser Labs WooCommerce – Commissions King plugin


The “WooCommerce Plugin News” box is always empty. “WooCommerce Plugins” widget contains “WooCommerce – Commissions King” item only. I suppose that it shows those plugins only that you have installed. Is it interesting for you? You know already that you use this plugin. You even remember that you paid for it. And there is no need in such widget in both cases, right? Any way there is the “Plugins” menu, where you may always check the current version of the plugin and updates availability.

I think, that widgets of this sort should be placed somewhere at the plugin settings pages (separate tab or not) and do not bother all users any time they login to their lovely WordPress.

Now let’s proceed with the “magic” part of this post. Right click on the widget you wish to hide. Select “Inspect element” menu item if you use Google Chrome browser or similar one, if you use other browser.

Woocommerce Plugin News widget div id

Woocommerce Plugin News widget div id


At the HTML code opened look for the div ID which contains the widget. In our example it is ‘woo_vl_news_widget’. The task is almost complete.
Open blog’s active theme functions.php file at your favorite text editor and add to the end this piece of code:

1
2
3
4
5
6
7
8
9
function remove_dashboard_widgets() {
    // remove WooCommerce Plugin News - by Visser Labs   
    remove_meta_box( 'woo_vl_news_widget', 'dashboard', 'normal');
 
    // remove WooCommerce Plugins - by Visser Labs
    remove_meta_box( 'woo_vm_status_widget', 'dashboard', 'normal');    
}
add_action('wp_user_dashboard_setup', 'remove_dashboard_widgets', 20);
add_action('wp_dashboard_setup', 'remove_dashboard_widgets', 20);

As you see we placed widget div IDs (‘woo_vl_news_widget’ and ‘woo_vm_status_widget’) found at page HTML to the remove_meta_box() function call.
We got it. Widgets which you don’t wish to see were hidden.
And you may do it with any widget now, just find its div ID, and remove_meta_box() with that ID as parameter.

In case you wish to hide some widget not from all users but from the user with selected user role or capability assigned, enclose code above with current_user_can() function result check, e.g. below:

1
2
3
4
5
6
7
8
9
10
11
if (current_user_can('subscriber')) {
    function remove_dashboard_widgets() {
        // remove WooCommerce Plugin News - by Visser Labs   
        remove_meta_box( 'woo_vl_news_widget', 'dashboard', 'normal');
 
        // remove WooCommerce Plugins - by Visser Labs
        remove_meta_box( 'woo_vm_status_widget', 'dashboard', 'normal');    
    }
    add_action('wp_user_dashboard_setup', 'remove_dashboard_widgets', 20);
    add_action('wp_dashboard_setup', 'remove_dashboard_widgets', 20);
} // if

In order to change WordPress user roles and capabilities I recommend you to use the “User Role Editor” plugin.

Happy blogging!