The WordPress Dashboard provides a range of widgets by default to display useful information and provide quick access to certain functions. However, sometimes you may want to remove certain widgets from the WordPress dashboard to declutter it or to provide a more focused experience for your users. Here’s an example code snippet to remove unwanted widgets from the Dashboard:
function wpsnippets_remove_dashboard_widgets() {
// Remove the "WordPress News" widget
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
// Remove the "Quick Draft" widget
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
// Remove the "Welcome" panel
remove_action( 'welcome_panel', 'wp_welcome_panel' );
}
add_action( 'admin_init', 'wpsnippets_remove_dashboard_widgets' );
In this code snippet, we define a function wpsnippets_remove_dashboard_widgets
that uses the remove_meta_box
function to remove the “WordPress News” and “Quick Draft” widgets from the Dashboard’s “side” section. We also use the remove_action
function to remove the “Welcome” panel entirely from the Dashboard. The remove_action
function is used because the “Welcome” panel is not technically a widget. Finally, we use the add_action
function to add the wpsnippets_remove_dashboard_widgets
function to the admin_init
hook. This hook is used to perform actions when the WordPress admin area is initialized.
With this code in place, you can remove widgets from the WordPress Dashboard for all users. You can modify the code to remove other widgets or panels as needed.