avatar Deluxe Blog Tips About Projects

Remove Dashboard Widgets In WordPress - The Better Way

Remove Dashboard Widgets In WordPress - The Better Way

There are several tutorials available in the internet showing how to remove dashboard widgets in WordPress. All of them use the Dashboard Widgets API, the solution is very similar to the following code (get from the Codex):

function example_remove_dashboard_widgets() {
 // Globalize the metaboxes array, this holds all the widgets for wp-admin
 global $wp_meta_boxes;

 // Remove the quickpress widget

 // Remove the incoming links widget

add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );

In my opinion, this is not a good approach. We touched the global WP variable $wp_meta_boxes, spent time finding keys for the widgets, and removed just by unset its value.

At a coder's point of view, I would like a function that handles all of this stuff, or making the job simpler.

Fortunately, I found that dashboard widgets are also meta boxes. They just appear in a special place. That mean we can use meta box functions remove_meta_box() on them.

Here's my version, that I believe it's really better:

add_action('admin_init', 'rw_remove_dashboard_widgets');
function rw_remove_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', 'normal');  // quick press
 remove_meta_box('dashboard_recent_drafts', 'dashboard', 'normal');  // recent drafts
 remove_meta_box('dashboard_primary', 'dashboard', 'normal');   // wordpress blog
 remove_meta_box('dashboard_secondary', 'dashboard', 'normal');   // other wordpress news

To use it, just put it in functions.php of your theme. If you want to keep some widgets, just comment out corresponding lines.

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com