Removing Widgets and Metaboxes from the WordPress Dashboard
To make it more convenient to work in the WordPress admin, sometimes you need to disable (delete) metaboxes and widgets, In this post let's see how to do it.
Removing Widgets from the Widget Admin Page
Option 1: To disable basic widgets in WordPress Dashboard use this code:
## Disabling standard WordPress widgets add_action( 'widgets_init', 'unregister_basic_widgets' ); function unregister_basic_widgets() { unregister_widget( 'WP_Widget_Pages' ); // Pages widget unregister_widget( 'WP_Widget_Calendar' ); // Calendar unregister_widget( 'WP_Widget_Archives' ); // Archives unregister_widget( 'WP_Widget_Links' ); // Links unregister_widget( 'WP_Widget_Meta' ); // Meta widget unregister_widget( 'WP_Widget_Search' ); // Search unregister_widget( 'WP_Widget_Text' ); // Text unregister_widget( 'WP_Widget_Categories' ); // Categories unregister_widget( 'WP_Widget_Recent_Posts' ); // Recent Posts unregister_widget( 'WP_Widget_Recent_Comments' ); // Recent Comments unregister_widget( 'WP_Widget_RSS' ); // RSS unregister_widget( 'WP_Widget_Tag_Cloud' ); // Tag cloud unregister_widget( 'WP_Nav_Menu_Widget' ); // Menu unregister_widget( 'WP_Widget_Media_Audio' ); // Audio unregister_widget( 'WP_Widget_Media_Video' ); // Video unregister_widget( 'WP_Widget_Media_Gallery' ); // Gallery unregister_widget( 'WP_Widget_Media_Image' ); // Image }
Option 2: To disable all widgets in WordPress, as well as disable the ability to register any widgets through the widgets_init hook, use the following code:
## Disable all WordPress widgets and all widgets created on the widgets_init hook remove_action( 'init', 'wp_widgets_init', 1 );
Use this code in the functions.php theme file.
Read more about how to remove widgets and other subtleties in the unregister_widget() function description.
Removing Metaboxes from the Site Dashboard
If you don't need any widgets in the WordPress Dashboard (console), you can usually turn them off in "Screen Settings" - a pop-up box that allows you to select the widgets you want.
However, this way of disabling widgets has at least two disadvantages:
-
Turning them off with checkmarks only hides the blocks (using CSS), rather than removing them from the code.
- If we make a custom site, it is better to hide some blocks at all, so that there are no blocks or checkmarks in "Screen Settings".
To avoid these disadvantages, widgets can be removed programmatically by using this code in the functions.php theme file:
## Removing widgets from the WordPress Dashboard add_action( 'wp_dashboard_setup', 'clear_wp_dash' ); function clear_wp_dash(){ $dash_side = & $GLOBALS['wp_meta_boxes']['dashboard']['side']['core']; $dash_normal = & $GLOBALS['wp_meta_boxes']['dashboard']['normal']['core']; unset( $dash_side['dashboard_quick_press'] ); // Quick publication unset( $dash_side['dashboard_recent_drafts'] ); // Recent Drafts unset( $dash_side['dashboard_primary'] ); // WordPress Blog unset( $dash_side['dashboard_secondary'] ); // Other WordPress News unset( $dash_normal['dashboard_incoming_links'] ); // Incoming Links unset( $dash_normal['dashboard_right_now'] ); // Right now unset( $dash_normal['dashboard_recent_comments'] ); // Recent Comments unset( $dash_normal['dashboard_plugins'] ); // Latest Plugins unset( $dash_normal['dashboard_activity'] ); // Activity unset( $dash_normal['dashboard_site_health'] ); // Site Health } ## Removing the "Welcome" widget remove_action( 'welcome_panel', 'wp_welcome_panel' );
In the code I signed which line is responsible for which widget. Here I specifically showed all the standard widgets of WordPress Dashboard, in fact in the code you need to leave only those lines that are responsible for widgets, which should be removed. I did not delete them in the code, but commented out, that is, if this code is placed in the theme file functions.php
, then in the console of WordPress will remain only 2 widgets: 'Half Drafts' and 'Right Now'.
Removing Metaboxes from the Site Network Console (multisite)
It's done exactly the same way here, only you need to use the hook wp_network_dashboard_setup:
## Removing widgets from the WordPress Multisite Console add_action( 'wp_network_dashboard_setup', 'clear_wp_network_dash' ); function clear_wp_network_dash(){ $dash_normal = & $GLOBALS['wp_meta_boxes']['dashboard-network']['normal']['core']; $dash_side = & $GLOBALS['wp_meta_boxes']['dashboard-network']['side']['core']; unset( $dash_normal['network_dashboard_right_now'] ); // Right Now unset( $dash_side['dashboard_primary'] ); // WordPress News and Events }
--
In addition to removing widgets, you can also create your own. How to do this is described in: