wp_add_dashboard_widget

The timeline below displays how wordpress function wp_add_dashboard_widget has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.8

/**
 * Adds a new dashboard widget.
 *
 * @since 2.7.0
 * @since 5.6.0 The `$context` and `$priority` parameters were added.
 *
 * @global callable[] $wp_dashboard_control_callbacks
 *
 * @param string   $widget_id        Widget ID  (used in the 'id' attribute for the widget).
 * @param string   $widget_name      Title of the widget.
 * @param callable $callback         Function that fills the widget with the desired content.
 *                                   The function should echo its output.
 * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
 * @param array    $callback_args    Optional. Data that should be set as the $args property of the widget array
 *                                   (which is the second parameter passed to your callback). Default null.
 * @param string   $context          Optional. The context within the screen where the box should display.
 *                                   Accepts 'normal', 'side', 'column3', or 'column4'. Default 'normal'.
 * @param string   $priority         Optional. The priority within the context where the box should show.
 *                                   Accepts 'high', 'core', 'default', or 'low'. Default 'core'.
 */
function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null, $context = 'normal', $priority = 'core')
{
    global $wp_dashboard_control_callbacks;
    $screen = get_current_screen();
    $private_callback_args = array('__widget_basename' => $widget_name);
    if (is_null($callback_args)) {
        $callback_args = $private_callback_args;
    } elseif (is_array($callback_args)) {
        $callback_args = array_merge($callback_args, $private_callback_args);
    }
    if ($control_callback && is_callable($control_callback) && current_user_can('edit_dashboard')) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id === $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    $side_widgets = array('dashboard_quick_press', 'dashboard_primary');
    if (in_array($widget_id, $side_widgets, true)) {
        $context = 'side';
    }
    $high_priority_widgets = array('dashboard_browser_nag', 'dashboard_php_nag');
    if (in_array($widget_id, $high_priority_widgets, true)) {
        $priority = 'high';
    }
    if (empty($context)) {
        $context = 'normal';
    }
    if (empty($priority)) {
        $priority = 'core';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $context, $priority, $callback_args);
}

WordPress Version: 5.6

/**
 * Adds a new dashboard widget.
 *
 * @since 2.7.0
 * @since 5.6.0 The `$context` and `$priority` parameters were added.
 *
 * @global callable[] $wp_dashboard_control_callbacks
 *
 * @param string   $widget_id        Widget ID  (used in the 'id' attribute for the widget).
 * @param string   $widget_name      Title of the widget.
 * @param callable $callback         Function that fills the widget with the desired content.
 *                                   The function should echo its output.
 * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
 * @param array    $callback_args    Optional. Data that should be set as the $args property of the widget array
 *                                   (which is the second parameter passed to your callback). Default null.
 * @param string   $context          Optional. The context within the screen where the box should display.
 *                                   Accepts 'normal', 'side', 'column3', or 'column4'. Default 'normal'.
 * @param string   $priority         Optional. The priority within the context where the box should show.
 *                                   Accepts 'high', 'core', 'default', or 'low'. Default 'core'.
 */
function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null, $context = 'normal', $priority = 'core')
{
    $screen = get_current_screen();
    global $wp_dashboard_control_callbacks;
    $private_callback_args = array('__widget_basename' => $widget_name);
    if (is_null($callback_args)) {
        $callback_args = $private_callback_args;
    } elseif (is_array($callback_args)) {
        $callback_args = array_merge($callback_args, $private_callback_args);
    }
    if ($control_callback && current_user_can('edit_dashboard') && is_callable($control_callback)) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id == $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    $side_widgets = array('dashboard_quick_press', 'dashboard_primary');
    if (in_array($widget_id, $side_widgets, true)) {
        $context = 'side';
    }
    $high_priority_widgets = array('dashboard_browser_nag', 'dashboard_php_nag');
    if (in_array($widget_id, $high_priority_widgets, true)) {
        $priority = 'high';
    }
    if (empty($context)) {
        $context = 'normal';
    }
    if (empty($priority)) {
        $priority = 'core';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $context, $priority, $callback_args);
}

WordPress Version: 5.5

/**
 * Adds a new dashboard widget.
 *
 * @since 2.7.0
 *
 * @global array $wp_dashboard_control_callbacks
 *
 * @param string   $widget_id        Widget ID  (used in the 'id' attribute for the widget).
 * @param string   $widget_name      Title of the widget.
 * @param callable $callback         Function that fills the widget with the desired content.
 *                                   The function should echo its output.
 * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
 * @param array    $callback_args    Optional. Data that should be set as the $args property of the widget array
 *                                   (which is the second parameter passed to your callback). Default null.
 */
function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null)
{
    $screen = get_current_screen();
    global $wp_dashboard_control_callbacks;
    $private_callback_args = array('__widget_basename' => $widget_name);
    if (is_null($callback_args)) {
        $callback_args = $private_callback_args;
    } elseif (is_array($callback_args)) {
        $callback_args = array_merge($callback_args, $private_callback_args);
    }
    if ($control_callback && current_user_can('edit_dashboard') && is_callable($control_callback)) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id == $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    $side_widgets = array('dashboard_quick_press', 'dashboard_primary');
    $location = 'normal';
    if (in_array($widget_id, $side_widgets, true)) {
        $location = 'side';
    }
    $high_priority_widgets = array('dashboard_browser_nag', 'dashboard_php_nag');
    $priority = 'core';
    if (in_array($widget_id, $high_priority_widgets, true)) {
        $priority = 'high';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args);
}

WordPress Version: 5.1

/**
 * Adds a new dashboard widget.
 *
 * @since 2.7.0
 *
 * @global array $wp_dashboard_control_callbacks
 *
 * @param string   $widget_id        Widget ID  (used in the 'id' attribute for the widget).
 * @param string   $widget_name      Title of the widget.
 * @param callable $callback         Function that fills the widget with the desired content.
 *                                   The function should echo its output.
 * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
 * @param array    $callback_args    Optional. Data that should be set as the $args property of the widget array
 *                                   (which is the second parameter passed to your callback). Default null.
 */
function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null)
{
    $screen = get_current_screen();
    global $wp_dashboard_control_callbacks;
    $private_callback_args = array('__widget_basename' => $widget_name);
    if (is_null($callback_args)) {
        $callback_args = $private_callback_args;
    } elseif (is_array($callback_args)) {
        $callback_args = array_merge($callback_args, $private_callback_args);
    }
    if ($control_callback && current_user_can('edit_dashboard') && is_callable($control_callback)) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id == $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    $side_widgets = array('dashboard_quick_press', 'dashboard_primary');
    $location = 'normal';
    if (in_array($widget_id, $side_widgets)) {
        $location = 'side';
    }
    $high_priority_widgets = array('dashboard_browser_nag', 'dashboard_php_nag');
    $priority = 'core';
    if (in_array($widget_id, $high_priority_widgets, true)) {
        $priority = 'high';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args);
}

WordPress Version: 4.6

/**
 * Adds a new dashboard widget.
 *
 * @since 2.7.0
 *
 * @global array $wp_dashboard_control_callbacks
 *
 * @param string   $widget_id        Widget ID  (used in the 'id' attribute for the widget).
 * @param string   $widget_name      Title of the widget.
 * @param callable $callback         Function that fills the widget with the desired content.
 *                                   The function should echo its output.
 * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
 * @param array    $callback_args    Optional. Data that should be set as the $args property of the widget array
 *                                   (which is the second parameter passed to your callback). Default null.
 */
function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null)
{
    $screen = get_current_screen();
    global $wp_dashboard_control_callbacks;
    $private_callback_args = array('__widget_basename' => $widget_name);
    if (is_null($callback_args)) {
        $callback_args = $private_callback_args;
    } else if (is_array($callback_args)) {
        $callback_args = array_merge($callback_args, $private_callback_args);
    }
    if ($control_callback && current_user_can('edit_dashboard') && is_callable($control_callback)) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id == $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    $side_widgets = array('dashboard_quick_press', 'dashboard_primary');
    $location = 'normal';
    if (in_array($widget_id, $side_widgets)) {
        $location = 'side';
    }
    $priority = 'core';
    if ('dashboard_browser_nag' === $widget_id) {
        $priority = 'high';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args);
}

WordPress Version: 4.5

/**
 * Adds a new dashboard widget.
 *
 * @since 2.7.0
 *
 * @global array $wp_dashboard_control_callbacks
 *
 * @param string   $widget_id        Widget ID  (used in the 'id' attribute for the widget).
 * @param string   $widget_name      Title of the widget.
 * @param callable $callback         Function that fills the widget with the desired content.
 *                                   The function should echo its output.
 * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
 * @param array    $callback_args    Optional. Data that should be set as the $args property of the widget array
 *                                   (which is the second parameter passed to your callback). Default null.
 */
function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null)
{
    $screen = get_current_screen();
    global $wp_dashboard_control_callbacks;
    if ($control_callback && current_user_can('edit_dashboard') && is_callable($control_callback)) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id == $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    $side_widgets = array('dashboard_quick_press', 'dashboard_primary');
    $location = 'normal';
    if (in_array($widget_id, $side_widgets)) {
        $location = 'side';
    }
    $priority = 'core';
    if ('dashboard_browser_nag' === $widget_id) {
        $priority = 'high';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args);
}

WordPress Version: 4.4

/**
 *
 * @global array   $wp_dashboard_control_callbacks
 *
 * @param string   $widget_id
 * @param string   $widget_name
 * @param callable $callback
 * @param callable $control_callback
 * @param array    $callback_args
 */
function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null)
{
    $screen = get_current_screen();
    global $wp_dashboard_control_callbacks;
    if ($control_callback && current_user_can('edit_dashboard') && is_callable($control_callback)) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id == $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    $side_widgets = array('dashboard_quick_press', 'dashboard_primary');
    $location = 'normal';
    if (in_array($widget_id, $side_widgets)) {
        $location = 'side';
    }
    $priority = 'core';
    if ('dashboard_browser_nag' === $widget_id) {
        $priority = 'high';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args);
}

WordPress Version: 4.3

/**
 *
 * @global array   $wp_dashboard_control_callbacks
 *
 * @param string   $widget_id
 * @param string   $widget_name
 * @param callback $callback
 * @param callback $control_callback
 * @param array    $callback_args
 */
function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null)
{
    $screen = get_current_screen();
    global $wp_dashboard_control_callbacks;
    if ($control_callback && current_user_can('edit_dashboard') && is_callable($control_callback)) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id == $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    $side_widgets = array('dashboard_quick_press', 'dashboard_primary');
    $location = 'normal';
    if (in_array($widget_id, $side_widgets)) {
        $location = 'side';
    }
    $priority = 'core';
    if ('dashboard_browser_nag' === $widget_id) {
        $priority = 'high';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args);
}

WordPress Version: 3.8

function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null)
{
    $screen = get_current_screen();
    global $wp_dashboard_control_callbacks;
    if ($control_callback && current_user_can('edit_dashboard') && is_callable($control_callback)) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id == $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    $side_widgets = array('dashboard_quick_press', 'dashboard_primary');
    $location = 'normal';
    if (in_array($widget_id, $side_widgets)) {
        $location = 'side';
    }
    $priority = 'core';
    if ('dashboard_browser_nag' === $widget_id) {
        $priority = 'high';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args);
}

WordPress Version: 3.7

function wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null)
{
    $screen = get_current_screen();
    global $wp_dashboard_control_callbacks;
    if ($control_callback && current_user_can('edit_dashboard') && is_callable($control_callback)) {
        $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
        if (isset($_GET['edit']) && $widget_id == $_GET['edit']) {
            list($url) = explode('#', add_query_arg('edit', false), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url($url) . '">' . __('Cancel') . '</a></span>';
            $callback = '_wp_dashboard_control_callback';
        } else {
            list($url) = explode('#', add_query_arg('edit', $widget_id), 2);
            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url("{$url}#{$widget_id}") . '" class="edit-box open-box">' . __('Configure') . '</a></span>';
        }
    }
    if (is_blog_admin()) {
        $side_widgets = array('dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_primary', 'dashboard_secondary');
    } else if (is_network_admin()) {
        $side_widgets = array('dashboard_primary', 'dashboard_secondary');
    } else {
        $side_widgets = array();
    }
    $location = 'normal';
    if (in_array($widget_id, $side_widgets)) {
        $location = 'side';
    }
    $priority = 'core';
    if ('dashboard_browser_nag' === $widget_id) {
        $priority = 'high';
    }
    add_meta_box($widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args);
}