TL;DR
- Use
wp_add_dashboard_widgetinsidewp_dashboard_setup. - Gate widgets with
current_user_canand keep output fast. - Remove default widgets to reduce clutter and focus admin attention.
Why Use Custom Dashboard Widgets?
The WordPress dashboard is the first screen admins see. A custom dashboard widget lets you surface the right data at the right time: editorial calendars, site health checks, sales metrics, support tickets, or onboarding links. These widgets reduce clicks and encourage consistent workflows.
The Core Hook: wp_dashboard_setup
Dashboard widgets are registered during the wp_dashboard_setup action. This is the correct place to register or remove widgets.
Minimal Working Example
This example adds a simple widget with capability checks and lightweight markup.
function fyrepress_add_dashboard_widget() {
if (!current_user_can('manage_options')) {
return;
}
wp_add_dashboard_widget(
'fyrepress_admin_widget',
'Site Overview',
'fyrepress_render_dashboard_widget'
);
}
add_action('wp_dashboard_setup', 'fyrepress_add_dashboard_widget');
function fyrepress_render_dashboard_widget() {
echo 'Quick links and site status go here.
';
}
FyrePress tool: Use the Dashboard Widget Creator to generate a full widget scaffold.
Permission Checks & Role Targeting
Always gate widgets with capabilities. For example, show revenue dashboards to admins but show editorial queues to editors. Use current_user_can and avoid role‑name checks when possible.
If you need role-specific output, you can branch inside the render callback and show different content blocks per capability.
Remove Default Widgets
Remove widgets you don’t use to reduce noise. Common candidates include “Quick Draft”, “Activity”, and “WordPress Events and News”.
function fyrepress_remove_default_widgets() {
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
remove_meta_box('dashboard_activity', 'dashboard', 'normal');
remove_meta_box('dashboard_primary', 'dashboard', 'side');
}
add_action('wp_dashboard_setup', 'fyrepress_remove_default_widgets', 20);
Layout & UX Best Practices
Keep widgets concise and scannable. Use short headings, 3–5 bullet items, and a clear primary action. If you need tables or charts, use a compact format and avoid heavy libraries inside the admin.
For multi‑tenant sites, hide widgets that aren’t relevant to the current user. Dashboards should feel personalized, not overwhelming.
Data Sources & Caching Strategy
If your widget needs remote data (e.g., revenue or ticket counts), fetch it on a schedule and store it in a transient. This avoids blocking the dashboard on slow APIs.
$data = get_transient('fp_widget_data');
if (!$data) {
$data = array('open_tickets' => 12, 'pending' => 3);
set_transient('fp_widget_data', $data, HOUR_IN_SECONDS);
}
Security & Sanitization
Always escape output in dashboard widgets. Use esc_html for text and esc_url for links. Never echo raw user input.
Performance & Caching
Dashboard widgets run on every admin load, so keep them fast. Avoid heavy queries or external API calls in the render function. If you need external data, cache it in a transient and refresh on a schedule.
Frequently Asked Questions
Can I show different dashboard widget content by user role?
Yes. Check capabilities and render role‑specific output.
How do I remove default WordPress dashboard widgets?
Use remove_meta_box inside wp_dashboard_setup.
Is it safe to run heavy queries in a dashboard widget?
Avoid heavy queries on every admin load. Cache results or load on demand.
Where should I add the widget code?
Use a plugin or mu‑plugin so the widget is not tied to a theme.
Key Takeaways
- Custom dashboard widgets improve admin workflows.
- Gate widgets with capabilities and keep output fast.
- Remove default widgets to reduce clutter.
Generate a widget scaffold instantly
Use the Dashboard Widget Creator to build a ready‑to‑paste widget.