• Home »
  • »
  • Modify WordPress Admin Plugin To Display As A WP Admin Dashboard Widget

Modify WordPress Admin Plugin To Display As A WP Admin Dashboard Widget

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.

    1. // Hook into the 'wp_dashboard_setup' action to register the plugins other functions
    2. add_action('wp_dashboard_setup', 'most_commented_add_dashboard_widgets' );
  2. Admin Dashboard Widget Display: Now add the below to actually display the widget.

    1. function most_commented_add_dashboard_widgets() {
    2. wp_add_dashboard_widget('most_commented_dashboard_widget', 'Most Commented Dashboard Widget', 'most_commented_dashboard_widget_function');
    3. }
  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.

    1. function most_commented_dashboard_widget_function() {
    2. mdv_most_commented(5,' ','');
    3. }

    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.

WordPress Plugin Development (Beginner’s Guide) (Paperback)

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