Yesterday I shared how to add some content to the “Right Now” WordPress dashboard widget. On occasion though you may have content that you would like to display on your dashboard that doesn’t quite fit into the “Right Now” widget. In that case you might want to create a custom dashboard widget. Here is all it takes.
Just copy and paste the code below to your site functionality plugin or create a new plugin.
[php]
// Function that output’s the contents of the dashboard widget
function my_dashboard_widget_function() {
// Enter your code here.
}
// Function that called by the action hook below to register the dashboard widget
function my_add_dashboard_widgets() {
wp_add_dashboard_widget(‘dashboard_widget’, ‘WP Ninjas Sales Stats’, ‘my_dashboard_widget_function’);
}
// Register the new dashboard widget into the ‘wp_dashboard_setup’ action
add_action(‘wp_dashboard_setup’, ‘my_add_dashboard_widgets’ );
[/php]
Pretty simple, right? Now I didn’t place any code in our dashboard widget because the possibilities are endless. My recent use case was to get all the sales from our transactions table and display them as a total and as individual products. This gives me a quick at-a-glance look at our sales and which products are doing the best.
What might you want to display in your WordPress Dashboard?
Leave a Reply