Post Pic

How to programatically remove WordPress dashboard widgets

Added in version 2.7, the Dashboard Widget API allow you to ad widgets to your WordPress admin dashboard. In this recipe, I’ll show you how you can easily remove them programatically.

Simply paste the following into your functions.php file. The code will remove all dashboard widgets, so you should comment lines related to wigets you'd like to keep.

function remove_dashboard_widgets() {
	global $wp_meta_boxes;

	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);

}

if (!current_user_can('manage_options')) {
	add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
}

Thanks to NoScope for this code!

By the way, did you had a look to my latest post on CatsWhoCode about WP 3.0 custom post types?

Related Posts

No related posts.

11 Responses

Jun 23 2010 16:21

Or you could always use the API that’s helpfully provided ;-)

add_action( ‘admin_menu’, ‘remove_dashboard_boxes’ );

function remove_dashboard_boxes() {
remove_meta_box( ‘dashboard_right_now’, ‘dashboard’, ‘core’ );
}

Jun 23 2010 19:00

I would like to know, what is the sense of the function, if I can disable widgets directly from dashboard using “Screen Options” tab?

Jun 23 2010 22:27

Thanx. Very helpful post for beginners.

Jun 24 2010 00:19

@Dimox:
This is very useful in keeping the admin interface clean and simple for clients.

Jun 24 2010 13:39

@Dimox : the widgets will be hided only in you local computer if you disable widgets using screen option, but if you use the fuction, it will be desabled for all the users and in any computer you use.
@NoScope : thanks for the code.

Jun 24 2010 15:40

@kamal: thanks for explanation.

Jun 25 2010 11:05

Nice Info! It was required. There are so many widgets which are cluttered on the dashboard. This recipe will certainly help me to get rid of those unwanted widgets.

Jul 03 2010 03:29

Thanks for the helpful snippet !

Aug 23 2010 03:27

This works only for the removal of default WP widgets. How can i remove dashboard widgets such as word tube statistics which was installed by a plugin wordtube?

Any suggestion?
Thx

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required