how to create wordpress dashboard widgets

How to Create WordPress Dashboard Widgets

Wouldn’t it be cool to have your very own custom WordPress dashboard widget- a widget that will be displayed on your Dashboard page upon logging into WordPress?

To get started, add the following contents to the functions.php file in your current theme directory:

Under the above code in the functions.php file, go ahead and add the following:

Lastly, we add the following code to the bottom of the above code:

Once the above code has been added to the current theme’s functions.php file, log in to your WordPress Dashboard and you should see your custom Dashboard widget.

Tip: If you don’t see your dashboard widget, click on “Screen Options” (this option is located at the top right of your WordPress Dashboard area) and make sure you check the box next to your widget’s title.

Now that we can see how easy it is to create a dashboard widget in WordPress- How about a real life example?

The above example will display a widget (in the dashboard) titled ‘Latest Comments’ with the last 10 comments with a status of ‘approved’.

Each comment will have the users name, a link to their website (if specified) and their comment, with a link to the post at the bottom, followed by a horizontal rule.

This widget will display (by default) on the dashboard of any user that is registered on your wordpress install. You can easily take this to the next level, with:

This is a nice plugin that I have used in the past for customization of the admin area.

Once its all setup you can configure the plugin and one of the options is to customize both admin and user dashboards or just customize the user dashboard.

When chooing the latter, you can then go and create some custom widgets and create a unique dashboard for your registered users.

Keep in mind, that you would then need to be using the functions script from the ag-custom-admin plugin directory- to ensure that the widgets are not displaying globally.

I hope you found this resource useful!

Interested in WordPress Plugin Development?

Wordpress Plugin Development Video Tutorial

At ZENVA we have a comprehensive video course on WordPress Plugin Development, check it out here.