Previously I wrote an article that detailed modifying the WordPress Most Commented plugin to display the most commented WordPress posts via the WP admin site. If you need more information on creating admin plugins or just wanted to glance over the article related to this one you can read it by clicking here. Something I did not include in that article was how to add code to the plugin that would also display a widget on the WP Admin dashboard. Below is basic information that should assist you in adding code that will display a dashboard widget.

Modify Plugin To Display A WordPress Admin Dashboard Widget:

It is nice to have all of the information you need regarding your WordPress blog available via the WP admin dashboard. The original article, located here, provides information that will assist creating a admin plugin and this information takes that a step further and extends that plugin to display it as a widget on the admin dashboard.

  1. Add Dashboard Widget Hook:You should add a hook that will register the plugins functions with the WP admin dashboard.
    // Hook into the 'wp_dashboard_setup' action to register the plugins other functions
    add_action('wp_dashboard_setup', 'most_commented_add_dashboard_widgets' );
  2. Admin Dashboard Widget Display: Now add the below to actually display the widget.
    function most_commented_add_dashboard_widgets() {
    wp_add_dashboard_widget('most_commented_dashboard_widget', 'Most Commented Dashboard Widget', 'most_commented_dashboard_widget_function');
  3. Admin Dashboard Widget Display Details: The mcd function is called from the above code so now it needs to be created with the details of what should display in the dashboard widget. The below uses the mdv_most_commented function to generate the display of the posts with the most comments.
    function most_commented_dashboard_widget_function() {
    mdv_most_commented(5,' ','');

    The above displays the 5 posts with the most comments.

  4. Verify New Dashboard Widget:Now with all of the above combined and added to the plugin you are generating the admin dashboard widget for login to your WordPress admin to verify the widget is displaying properly on the WordPress dashboard.

The above just provides simple examples of the minimal amount of code needed to display a WordPress admin dashboard widget.

List Price: $39.99 USD
New From: $11.43 USD In Stock
Used from: $5.00 USD In Stock

List Price: $39.99 USD
New From: $10.99 USD In Stock
Used from: $0.01 USD In Stock

Tags: , , , , , , , , ,
2 Responses to “Modify WordPress Admin Plugin To Display As A WP Admin Dashboard Widget”
  1. Artem says:

    Is there a way to add a new widget to the dashboard with ajax? After the dashboard finished loading?

    Here your hooking to the wp_dashboard_setup, and it only adds your widget while this is running. Is there a way?


    alex Reply:

    Hello Artem,

    I am sure there is a way. I assume you just need to make sure that the widget you are installing loads last. I am not sure right off though about how to go about this the easiest way as I think all of the widgets are created on the page at the same time.

    Did you come up with a solution? If not let us know and we can look into it when time allows to see if we can come up with a way to accomplish this.



Leave a Reply

*Type the letter/number combination in the abvoe field before clicking submit.