THE PENDING DRAFT

Add a custom WordPress Dashboard Widget

August 26, 2013

Sometimes you want to show a custom widget in the WordPress Dashboard. I use this function a lot, for example on client sites to provide some direct access to contact information for support or to show some custom messages to guide your clients with your theme, plugin or service. This little snippet will create a new widget and show it in the Admin Dashboard. Nothing more.

// Create the function for the content of our custom widget
function pdr_dashboard_widget_function() {
    echo "Display whatever it is you want to display inside your custom dashboard widget";
}

// Add our custom dashboard widget
function pdr_add_dashboard_widgets() {
    wp_add_dashboard_widget('pdr_dashboard_widget', 'Custom Dashboard Widget', 'pdr_dashboard_widget_function');
}

// Hook everything into the 'wp_dashboard_setup' action to register our functions
add_action('wp_dashboard_setup', 'pdr_add_dashboard_widgets' );

 

Put that code inside your functions.php, or inside a custom plugin and you will have a basic widget right in your WP Dashboard.

Leave your comment