RSS

How To Add Custom Dashboard Widgets to WordPress

13 Sep

After signing in to WordPress admin, you can see various dashboard widgets like Right Now, Quickpress etc. Let us see how can we add our own dashboard widget. If you are developing a theme, you can write the needed code inside functions.php file. If you are developing a plugin, you can write the code anywhere in the plugin file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
// Function that outputs the contents of the dashboard widget
function dashboard_widget_function() {
    echo “Welcome to cube3x statistics”;
}
// Function used in the action hook
function add_dashboard_widgets() {
    wp_add_dashboard_widget(‘cube3x_dashboard_widget’, ‘Custom Dashboard Widget’, ‘dashboard_widget_function’);
}
// Register the new dashboard widget with the ‘wp_dashboard_setup’ action
add_action(‘wp_dashboard_setup’, ‘add_dashboard_widgets’ );
?>
Advertisements
 
Leave a comment

Posted by on September 13, 2013 in Wordpress

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: