Remove Dashboard Clutter
Overview
Remove default WordPress dashboard widgets and the Welcome panel for a cleaner admin dashboard.
The snippet removes common core dashboard widgets, disables the Welcome panel, and hides empty dashboard widget containers on the dashboard screen.
Variants
- Procedural
- OOP
<?php
/**
* Remove default WordPress dashboard clutter.
*/
if ( ! function_exists( 'mac_get_dashboard_clutter_widgets' ) ) {
/**
* Dashboard widget IDs and contexts.
*
* @return array<string,string>
*/
function mac_get_dashboard_clutter_widgets(): array {
return [
'dashboard_activity' => 'normal',
'dashboard_right_now' => 'normal',
'dashboard_incoming_links' => 'normal',
'dashboard_plugins' => 'normal',
'dashboard_quick_press' => 'side',
'dashboard_recent_drafts' => 'side',
'dashboard_primary' => 'side',
'dashboard_secondary' => 'side',
];
}
}
/**
* Remove common non-comment dashboard widgets.
*/
if ( ! function_exists( 'mac_remove_dashboard_clutter_widgets' ) ) {
function mac_remove_dashboard_clutter_widgets(): void {
foreach ( mac_get_dashboard_clutter_widgets() as $widget_id => $context ) {
remove_meta_box( $widget_id, 'dashboard', $context );
}
}
}
add_action( 'wp_dashboard_setup', 'mac_remove_dashboard_clutter_widgets', 20 );
/**
* Remove the Welcome panel.
*/
if ( ! function_exists( 'mac_remove_dashboard_welcome_panel' ) ) {
function mac_remove_dashboard_welcome_panel(): void {
remove_action( 'welcome_panel', 'wp_welcome_panel' );
}
}
add_action( 'welcome_panel', 'mac_remove_dashboard_welcome_panel', 0 );
add_filter( 'show_welcome_panel', '__return_false' );
/**
* Hide empty dashboard containers for a cleaner UI.
*/
if ( ! function_exists( 'mac_hide_empty_dashboard_containers' ) ) {
function mac_hide_empty_dashboard_containers(): void {
echo '<style>#dashboard-widgets .empty-container{display:none}</style>';
}
}
add_action( 'admin_head-index.php', 'mac_hide_empty_dashboard_containers' );
<?php
/**
* Remove default WordPress dashboard clutter.
*
* @package mac-core
*/
declare(strict_types=1);
namespace MacCore\Services\Core;
use MacCore\Contracts\Service;
final class RemoveDashboardClutter implements Service
{
/**
* Dashboard widget IDs and contexts.
*
* @var array<string,string>
*/
private const DASHBOARD_WIDGETS = [
'dashboard_activity' => 'normal',
'dashboard_right_now' => 'normal',
'dashboard_incoming_links' => 'normal',
'dashboard_plugins' => 'normal',
'dashboard_quick_press' => 'side',
'dashboard_recent_drafts' => 'side',
'dashboard_primary' => 'side',
'dashboard_secondary' => 'side',
];
/**
* Register WordPress hooks.
*/
public function register(): void
{
\add_action(
'wp_dashboard_setup',
[$this, 'remove_dashboard_widgets'],
20
);
\add_action(
'welcome_panel',
[$this, 'remove_welcome_panel'],
0
);
\add_filter(
'show_welcome_panel',
'__return_false'
);
\add_action(
'admin_head-index.php',
[$this, 'hide_empty_dashboard_containers']
);
}
/**
* Remove common non-comment dashboard widgets.
*/
public function remove_dashboard_widgets(): void
{
foreach ( self::DASHBOARD_WIDGETS as $widget_id => $context ) {
\remove_meta_box( $widget_id, 'dashboard', $context );
}
}
/**
* Remove the Welcome panel.
*/
public function remove_welcome_panel(): void
{
\remove_action( 'welcome_panel', 'wp_welcome_panel' );
}
/**
* Hide empty dashboard containers for a cleaner UI.
*/
public function hide_empty_dashboard_containers(): void
{
echo '<style>#dashboard-widgets .empty-container{display:none}</style>';
}
}