How to Add a Widget to Your WordPress Admin Dashboard

Do you want to learn how to add a widget to your WordPress admin dashboard? In this guide, we’ll walk you through the process of adding a widget to your WordPress admin dashboard.

The WordPress platform offers a plethora of customizable elements to help create a website that perfectly suits your needs. Among these elements are widgets – a significant feature that can extend the functionality of your site. These handy tools can be found in various areas of your site, including the sidebar, footer, and more. But did you know you can also add widgets to your WordPress admin dashboard? These can provide quick insights and streamline your workflow.

What Are Dashboard Widgets?

Dashboard widgets in WordPress are modules that offer useful information and features at a glance once you log into your admin area. They can provide a wide array of functionalities, from displaying recent activity, quick draft notes, site stats, to enabling shortcuts to essential features.

Guide to Add a Widget to Your WordPress Admin Dashboard Without a Plugin

While plugins offer a straightforward way to add widgets, you can also add them directly using PHP code. This is a more advanced method and is recommended only if you are comfortable working with code and understand the WordPress functions and structure.

You can add the code either in your theme’s functions.php file or as a custom plugin. Here’s an example of how you can create a simple dashboard widget:

add_action('wp_dashboard_setup', 'example_add_dashboard_widgets');
function example_add_dashboard_widgets() {
    wp_add_dashboard_widget( 'my_dashboard_widget', 'My Dashboard Widget', 'my_dashboard_widget_function' );
    // Globalize the metaboxes array, this holds all the widgets for wp-admin
    global $wp_meta_boxes;
    // Get the regular dashboard widgets array with our new widget appearing at the very end
    $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
    // Backup and delete our new dashboard widget from the end of the array
    $example_widget_backup = array( 'example_dashboard_widget' => $normal_dashboard['example_dashboard_widget'] );
    unset( $normal_dashboard['example_dashboard_widget'] );
    // Merge the two arrays together so our widget is at the beginning
    $sorted_dashboard = array_merge( $example_widget_backup, $normal_dashboard );
    // Save the sorted array back into the original metaboxes
    $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;

function my_dashboard_widget_function() {
    // You can remove this line and start placing your own codes.
    echo "Start getting your hands dirty on this area.";

This is the output:



Adding widgets to your WordPress admin dashboard is an excellent way to increase your site’s functionality and streamline your tasks. Whether you choose to use a plugin or code, you now have the knowledge to customize your dashboard as you see fit. However, always remember to backup your WordPress site before making any changes, just in case anything goes wrong. Happy customizing!

See Also