How to Add a Custom Widget to WordPress Dashboard

In some situations, especially on multi-user blogs, it may be useful to completely remove widgets from the interface. By default, each individual user can turn off any given widget using the Screen Options (this option is located at the top right of your WordPress Dashboard area), but for non-technical users, it might be nicer for them to not see it at all.

non-technical-users

There are plenty of new themes coming out for WordPress every day, but none of them utilize a feature that remove default widgets or add custom dashboard widgets. In this article, we will show you how easy to remove the default widget, as well as add your own dashboard widget to display any information that you want.

dashboard

Remove default widget in WordPress Dashboard

Following our guide on series “Customize your Admin Area in WordPress”, and step How to Add a Custom Logo to WordPress Login Site you could be know how to creat your own plugin as well as basically modify the code.
So today we will proceed to customize the components inside the admin page, and firstly, we will show you how to remove default widget in WordPress Dashboard.

Open the custom-admin plugin that you have made from the previous tutorial. You simply adding PHP code to the custom-admin.php file as below:

remove_meta_box( 'dashboard_activity', 'dashboard', 'side' ); This code simply required to remove the widget that have been listed from the WordPress Dashboard screen. You can view the names list of the default dashboard widgets here then similarly copy and replace the widget’s name to this function.

remove-meta-box

If you want to remove Welcome to WordPress widget, you need to use this function:
remove_action( 'welcome_panel', 'wp_welcome_panel' ); and put it out of function remove_default_admin_widget ()

Add custom widget in WordPress Dashboard

Normally, when developing websites for clients, we may need to use the dashboard to post a note to remind, or advanced functions such as get the latest news on your site, or update rate of gold price, ect… depending on the extent of your coding skill.

In this section, I will guide how to add a simple widget to WordPress dashboard. This code can be very helpful when creating custom themes for clients.
Simply open your functions.php file and add the following code:

As you can see, I declare this function:

This function include of:
tp_notice: the widget ID, the ID must not overlap with other widgets.
SharePress note: The widget’s title that you want users can see.
create_admin_widget_notice_callback: Name of the function that will execute in the widget.

Now we will proceed to declare create_admin_widget_notice_callback function:

Once the above code has been added, save changes of your custom-admin.php (you also add above PHP code to functions.php file in your current theme directory) now you can go to Dashboard and see your result:

sharepress-note

This widget will display by default on the WP dashboard of any user that is registered on your wordpress install.
Notice: If you don’t see your dashboard widget, click on “Screen Options” and make sure you check the box next to your widget’s title.
—————-

Well, Hopefully this article is helpful enough to helps you know how to remove default dashboard widget as well as add your custom widget in WordPress dashboard. If you have any questions then don’t hesitate to put it up in the comments
See you again in orther tutorials!

 

Leave a Reply

Your email address will not be published. Required fields are marked *