What’s the right way to add a custom dashboard widget in WordPress admin?
Asked on Sep 26, 2025
Answer
To add a custom dashboard widget in WordPress, you can use the `wp_dashboard_setup` action hook to register your widget. This involves creating a function to output the widget's content and another function to register the widget itself.
<!-- BEGIN COPY / PASTE -->
function my_custom_dashboard_widget() {
echo "Welcome to my custom dashboard widget!";
}
function add_my_custom_dashboard_widget() {
wp_add_dashboard_widget(
'custom_dashboard_widget', // Widget slug.
'My Custom Widget', // Title.
'my_custom_dashboard_widget' // Display function.
);
}
add_action('wp_dashboard_setup', 'add_my_custom_dashboard_widget');
<!-- END COPY / PASTE -->Additional Comment:
- Place this code in your theme's `functions.php` file or a custom plugin.
- The `wp_dashboard_setup` hook is used to ensure the widget is registered at the right time.
- Customize the widget content by modifying the `my_custom_dashboard_widget` function.
Recommended Links: