Like the blog? Get the book »

Disable Default Dashboard Widgets in WordPress

Disable Default Dashboard Widgets in WordPress

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):

Update: added lines to disable dashboard widgets for Yoast SEO and Gravity Forms.
/*
	Disable Default Dashboard Widgets
	@ https://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', 'disable_default_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!

The new way to remove meta boxes uses remove_meta_box() for each widget. For example, to remove all default dashboard widgets:

remove_meta_box('dashboard_right_now', 'dashboard', 'normal');        // Right Now
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');  // Recent Comments
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');   // Incoming Links
remove_meta_box('dashboard_plugins', 'dashboard', 'normal');          // Plugins
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');        // Quick Press
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');      // Recent Drafts
remove_meta_box('dashboard_primary', 'dashboard', 'side');            // WordPress blog
remove_meta_box('dashboard_secondary', 'dashboard', 'side');          // Other WordPress News

// use 'dashboard-network' as second parameter to remove widgets from network dashboard

To illustrate how to transition to the new technique. Up until recently I was using this as drop-in for disabling all the useless front-end and dashboard stuff:

function shapeSpace_wp_dashboard_setup() {
	
	if (!current_user_can('manage_options')) {
		
		unset($wp_meta_boxes['dashboard']['normal']['high']['dashboard_browser_nag']);
		unset($wp_meta_boxes['dashboard']['normal']['high']['dashboard_php_nag']);
		unset($wp_meta_boxes['dashboard']['normal']['core']['health_check_status']);
		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']['network_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']);
		
	}
	
}
add_action('wp_dashboard_setup', 'shapeSpace_wp_dashboard_setup');

That works great but the newer way of doing it is even better. Here is what I’m using now:

function shapeSpace_wp_dashboard_setup() {
	
	if (!current_user_can('manage_options')) {
		
		remove_action('welcome_panel', 'wp_welcome_panel');
		
		remove_meta_box('dashboard_primary',       'dashboard', 'side');
		remove_meta_box('dashboard_secondary',     'dashboard', 'side');
		remove_meta_box('dashboard_quick_press',   'dashboard', 'side');
		remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
		
		remove_meta_box('dashboard_php_nag',           'dashboard', 'normal');
		remove_meta_box('dashboard_browser_nag',       'dashboard', 'normal');
		remove_meta_box('health_check_status',         'dashboard', 'normal');
		remove_meta_box('dashboard_activity',          'dashboard', 'normal');
		remove_meta_box('dashboard_right_now',         'dashboard', 'normal');
		remove_meta_box('network_dashboard_right_now', 'dashboard', 'normal');
		remove_meta_box('dashboard_recent_comments',   'dashboard', 'normal');
		remove_meta_box('dashboard_incoming_links',    'dashboard', 'normal');
		remove_meta_box('dashboard_plugins',           'dashboard', 'normal');
		
	}
	
}
add_action('wp_dashboard_setup', 'shapeSpace_wp_dashboard_setup');

Notice I added the Welcome Panel in there, feel free to remove and/or customize things however is needed. Hopefully it helps someone. Cheers!

6 responses

  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!

Comments are closed for this post. Contact us with any critical information.
© 2009–2024 Digging Into WordPress Powered by WordPress Monzilla Media shapeSpace