DiggingIntoWordPress

by Chris Coyier & Jeff Starr

Disable Default Dashboard Widgets

Posted by on

Continuing with tips for customizing the WordPress Dashboard, here is a look at one way to remove unwanted widgets and clean up the default WP Dashboard.

Using WordPress to build sites like Plugin Planet, it’s usually necessary to customize the Dashboard by removing some default widgets and adding some of my own. No big deal, but the code required to disable the default widgets seems to evolve along with WordPress. So if you have any sites where you’ve disabled default dashboard widgets, it may be worthwhile to check that the code is still working. Either way, here is a function that works great with current WordPress (3.8):

/*
	Disable Default Dashboard Widgets
	@ http://digwp.com/2014/02/disable-default-dashboard-widgets/
*/
function disable_default_dashboard_widgets() {
	global $wp_meta_boxes;
	// wp..
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
	// bbpress
	unset($wp_meta_boxes['dashboard']['normal']['core']['bbp-dashboard-right-now']);
	// yoast seo
	unset($wp_meta_boxes['dashboard']['normal']['core']['yoast_db_widget']);
	// gravity forms
	unset($wp_meta_boxes['dashboard']['normal']['core']['rg_forms_dashboard']);
}
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets', 999);

When added to the theme’s functions.php file, this code will disable all default widgets in the WP Dashboard. It’s drastic, so be sure to comment-out or remove any lines that aren’t required.

The code itself is straightforward, basically a function that uses unset to disable the default widgets, “Recent Activity”, “Right Now”, and so forth. Note that the last line in the function is to disable the default bbPress widget (remove if not needed). Lastly the function is hooked into WordPress via wp_dashboard_setup. That’s all there is to it, just add the code to your theme’s functions file (or plugin or whatever) and done. At least, until things change again.

Update: added lines to disable dashboard widgets for Yoast SEO and Gravity Forms.

FWIW

The old way uses remove_meta_box() for each widget, for example:

remove_meta_box('dashboard_right_now', 'dashboard', 'core');
remove_meta_box('dashboard_recent_comments', 'dashboard', 'core');
remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
remove_meta_box('dashboard_plugins', 'dashboard', 'core');
remove_meta_box('dashboard_quick_press', 'dashboard', 'core');
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'core');
remove_meta_box('dashboard_primary', 'dashboard', 'core');
remove_meta_box('dashboard_secondary', 'dashboard', 'core');
.
.
.

I’ve seen other techniques as well, but I think with 3.8 going the unset methodology seems the way to go.

6 Responses Leave a reply

  1. Great tip. Worked perfectly. I love to have my WordPress Dashboard clean and tidy so this was right up my street.

  2. why is using global variables considered a better way? remove_meta_box seems much nicer and cleaner. are there any reasons the long and less readable unset $wp_meta_boxes... code should be used?

  3. Awesome tip, worked perfectly. Thanks!

  4. For the copy and pasters out there… there is an extraneous apostrophe within ['yoast_db_widget'']. Otherwise, great tip. Thanks!

Leave a reply

Please wrap code with <code> tags. You may also use these tags.

Code is poetry