Codex

Function Reference/wp add dashboard widget

Contents

Description

This function adds a new widgets to the administration dashboard using wordpress Dashboard Widgets API.

Usage

<?php wp_add_dashboard_widget($widget_id$widget_name$callback$control_callback ); ?>

Parameters

$widget_id
(integer) (required) an identifying slug for your widget. This will be used as its css class and its key in the array of widgets.
Default: None
$widget_name
(string) (required) this is the name your widget will display in its heading.
Default: None
$callback
(string) (required) The name of a function you create that will display the actual contents of your widget.
Default: None
$control_callback
(string) (optional) The name of a function you create that will handle submission of widget options forms, and will also display the form elements.
Default:

Examples

Adding Dashboard Widgets

Here is a simple dashboard widget:

// Function that output's the contents of the dashboard widget
function dashboard_widget_function() {
	echo "Hello World, this id my first Dashboard Widget!";
}

// Function that beeng used in the action hook
function add_dashboard_widgets() {
	wp_add_dashboard_widget('dashboard_widget', 'Example Dashboard Widget', 'dashboard_widget_function');
}

// Register the new dashboard widget into the 'wp_dashboard_setup' action
add_action('wp_dashboard_setup', 'add_dashboard_widgets' );

Running Dashboard Widgets

To run the function use this code:

do_action( 'wp_dashboard_setup' );

Change Log

Since: 2.7.0

Source File

wp_add_dashboard_widget() is located in /wp-admin/includes/dashboard.php.

Related

See also index of Function Reference and index of Template Tags.