How to create a Dashboard Widget WordPress

You can easily create your own dashboard widgets using the Dashboard Widgets API

Basically you can add your own function when WordPress is showing the dasboard.

So, in fact, you could do everything.

Here in CodeGround I created a widget wich shows the most views posts using the data from an other plugin.

Ok, less talking and more coding...


First of all we need to add the widget itself.

Fill the 3 parameters with your widget function, widget title and widget content function.

function mywidget_add_dashboard_widgets() { wp_add_dashboard_widget('mywidget_dashboard_widget', 'My Widget Title', 'my_function'); }

Now add the widget you have created to the Dashboard.

add_action('wp_dashboard_setup', 'mywidget_add_dashboard_widgets' );

Finally create the widget content function.

function my_function(){ echo "Hello World!"; }


This is how it will looks like.


Read the codex for further information πŸ˜‰

Leave a Reply

Add <code> Some Code </code> by using this tags.