WordPress Dashboard Widgets API

The Dashboard Widgets API in WordPress allows developers to create and manage custom widgets that appear on the WordPress Admin Dashboard, providing users quick access to custom content, statistics, notifications, or administrative tools.

Why Use Dashboard Widgets?

Dashboard widgets are helpful for:

  • Displaying site analytics or key metrics
  • Offering quick links or shortcuts
  • Providing custom notifications or system statuses
  • Enhancing admin experience with useful insights

Core Functions

  • wp_add_dashboard_widget() — Adds a new widget to the dashboard.
  • remove_meta_box() — Removes existing dashboard widgets.

Creating a Custom Dashboard Widget

Example:

function my_custom_dashboard_widget() {
echo '<p>Welcome to your custom admin widget!</p>';
}

function add_my_dashboard_widget() {
wp_add_dashboard_widget(
'my_dashboard_widget', // Widget slug (unique ID)
'My Custom Widget', // Title displayed
'my_custom_dashboard_widget' // Callback function
);
}

add_action( 'wp_dashboard_setup', 'add_my_dashboard_widget' );

Removing Default Dashboard Widgets

Example (removing Quick Draft widget):

function remove_dashboard_widgets() {
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
}
add_action('wp_dashboard_setup', 'remove_dashboard_widgets');

Use Cases

  • Agency dashboards (client metrics, contact info)
  • Plugin status (license, update notifications)
  • Custom welcome panels or documentation
  • Project-specific information

Best Practices

  • Keep dashboard widgets simple, lightweight, and helpful
  • Avoid excessive loading time or complex queries
  • Provide clear, actionable content or metrics