Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Goodnight

Add Custom Widget to WordPress Dashboard

SnippetsWordPress

About a 1 minute read

"The art of living… is neither careless drifting on the one hand nor fearful clinging to the past on the other. It consists in being sensitive to each moment, in regarding it as utterly new and unique, in having the mind open and wholly receptive."

Alan Watts


1
2
3
4
5
6
7
8
9
10
11
12
13
14
//add custom widget to dashboard
add_action('wp_dashboard_setup', 'custom_dashboard_widgets');

function custom_dashboard_widgets(){
    //first parameter is the ID of the widget (the div holding the widget will have that ID)
    //second parameter is title (shown in the header of the widget) -> see picture bellow
    //third parameter is the function name we are calling to get the content of our widget
    wp_add_dashboard_widget('my_custom_widget_id', 'My Widget Title', 'my_custom_widget');
}

function my_custom_widget() {
    //the content of our custom widget
    echo '<p>The content of the widget goes here.</p>';
}