the_widget

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

WordPress Version: 5.3

/**
 * Output an arbitrary widget as a template tag.
 *
 * @since 2.8.0
 *
 * @global WP_Widget_Factory $wp_widget_factory
 *
 * @param string $widget   The widget's PHP class name (see class-wp-widget.php).
 * @param array  $instance Optional. The widget's instance settings. Default empty array.
 * @param array  $args {
 *     Optional. Array of arguments to configure the display of the widget.
 *
 *     @type string $before_widget HTML content that will be prepended to the widget's HTML output.
 *                                 Default `<div class="widget %s">`, where `%s` is the widget's class name.
 *     @type string $after_widget  HTML content that will be appended to the widget's HTML output.
 *                                 Default `</div>`.
 *     @type string $before_title  HTML content that will be prepended to the widget's title when displayed.
 *                                 Default `<h2 class="widgettitle">`.
 *     @type string $after_title   HTML content that will be appended to the widget's title when displayed.
 *                                 Default `</h2>`.
 * }
 */
function the_widget($widget, $instance = array(), $args = array())
{
    global $wp_widget_factory;
    if (!isset($wp_widget_factory->widgets[$widget])) {
        _doing_it_wrong(__FUNCTION__, sprintf(
            /* translators: %s: register_widget() */
            __('Widgets need to be registered using %s, before they can be displayed.'),
            '<code>register_widget()</code>'
        ), '4.9.0');
        return;
    }
    $widget_obj = $wp_widget_factory->widgets[$widget];
    if (!$widget_obj instanceof WP_Widget) {
        return;
    }
    $default_args = array('before_widget' => '<div class="widget %s">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    $args = wp_parse_args($args, $default_args);
    $args['before_widget'] = sprintf($args['before_widget'], $widget_obj->widget_options['classname']);
    $instance = wp_parse_args($instance);
    /** This filter is documented in wp-includes/class-wp-widget.php */
    $instance = apply_filters('widget_display_callback', $instance, $widget_obj, $args);
    if (false === $instance) {
        return;
    }
    /**
     * Fires before rendering the requested widget.
     *
     * @since 3.0.0
     *
     * @param string $widget   The widget's class name.
     * @param array  $instance The current widget instance's settings.
     * @param array  $args     An array of the widget's sidebar arguments.
     */
    do_action('the_widget', $widget, $instance, $args);
    $widget_obj->_set(-1);
    $widget_obj->widget($args, $instance);
}

WordPress Version: 5.1

/**
 * Output an arbitrary widget as a template tag.
 *
 * @since 2.8.0
 *
 * @global WP_Widget_Factory $wp_widget_factory
 *
 * @param string $widget   The widget's PHP class name (see class-wp-widget.php).
 * @param array  $instance Optional. The widget's instance settings. Default empty array.
 * @param array  $args {
 *     Optional. Array of arguments to configure the display of the widget.
 *
 *     @type string $before_widget HTML content that will be prepended to the widget's HTML output.
 *                                 Default `<div class="widget %s">`, where `%s` is the widget's class name.
 *     @type string $after_widget  HTML content that will be appended to the widget's HTML output.
 *                                 Default `</div>`.
 *     @type string $before_title  HTML content that will be prepended to the widget's title when displayed.
 *                                 Default `<h2 class="widgettitle">`.
 *     @type string $after_title   HTML content that will be appended to the widget's title when displayed.
 *                                 Default `</h2>`.
 * }
 */
function the_widget($widget, $instance = array(), $args = array())
{
    global $wp_widget_factory;
    if (!isset($wp_widget_factory->widgets[$widget])) {
        /* translators: %s: register_widget() */
        _doing_it_wrong(__FUNCTION__, sprintf(__('Widgets need to be registered using %s, before they can be displayed.'), '<code>register_widget()</code>'), '4.9.0');
        return;
    }
    $widget_obj = $wp_widget_factory->widgets[$widget];
    if (!$widget_obj instanceof WP_Widget) {
        return;
    }
    $default_args = array('before_widget' => '<div class="widget %s">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    $args = wp_parse_args($args, $default_args);
    $args['before_widget'] = sprintf($args['before_widget'], $widget_obj->widget_options['classname']);
    $instance = wp_parse_args($instance);
    /**
     * Fires before rendering the requested widget.
     *
     * @since 3.0.0
     *
     * @param string $widget   The widget's class name.
     * @param array  $instance The current widget instance's settings.
     * @param array  $args     An array of the widget's sidebar arguments.
     */
    do_action('the_widget', $widget, $instance, $args);
    $widget_obj->_set(-1);
    $widget_obj->widget($args, $instance);
}

WordPress Version: 4.9

/**
 * Output an arbitrary widget as a template tag.
 *
 * @since 2.8.0
 *
 * @global WP_Widget_Factory $wp_widget_factory
 *
 * @param string $widget   The widget's PHP class name (see class-wp-widget.php).
 * @param array  $instance Optional. The widget's instance settings. Default empty array.
 * @param array  $args {
 *     Optional. Array of arguments to configure the display of the widget.
 *
 *     @type string $before_widget HTML content that will be prepended to the widget's HTML output.
 *                                 Default `<div class="widget %s">`, where `%s` is the widget's class name.
 *     @type string $after_widget  HTML content that will be appended to the widget's HTML output.
 *                                 Default `</div>`.
 *     @type string $before_title  HTML content that will be prepended to the widget's title when displayed.
 *                                 Default `<h2 class="widgettitle">`.
 *     @type string $after_title   HTML content that will be appended to the widget's title when displayed.
 *                                 Default `</h2>`.
 * }
 */
function the_widget($widget, $instance = array(), $args = array())
{
    global $wp_widget_factory;
    if (!isset($wp_widget_factory->widgets[$widget])) {
        /* translators: %s: register_widget() */
        _doing_it_wrong(__FUNCTION__, sprintf(__('Widgets need to be registered using %s, before they can be displayed.'), '<code>register_widget()</code>'), '4.9.0');
        return;
    }
    $widget_obj = $wp_widget_factory->widgets[$widget];
    if (!$widget_obj instanceof WP_Widget) {
        return;
    }
    $default_args = array('before_widget' => '<div class="widget %s">', 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    $args = wp_parse_args($args, $default_args);
    $args['before_widget'] = sprintf($args['before_widget'], $widget_obj->widget_options['classname']);
    $instance = wp_parse_args($instance);
    /**
     * Fires before rendering the requested widget.
     *
     * @since 3.0.0
     *
     * @param string $widget   The widget's class name.
     * @param array  $instance The current widget instance's settings.
     * @param array  $args     An array of the widget's sidebar arguments.
     */
    do_action('the_widget', $widget, $instance, $args);
    $widget_obj->_set(-1);
    $widget_obj->widget($args, $instance);
}

WordPress Version: 4.4

/**
 * Output an arbitrary widget as a template tag.
 *
 * @since 2.8.0
 *
 * @global WP_Widget_Factory $wp_widget_factory
 *
 * @param string $widget   The widget's PHP class name (see class-wp-widget.php).
 * @param array  $instance Optional. The widget's instance settings. Default empty array.
 * @param array  $args {
 *     Optional. Array of arguments to configure the display of the widget.
 *
 *     @type string $before_widget HTML content that will be prepended to the widget's HTML output.
 *                                 Default `<div class="widget %s">`, where `%s` is the widget's class name.
 *     @type string $after_widget  HTML content that will be appended to the widget's HTML output.
 *                                 Default `</div>`.
 *     @type string $before_title  HTML content that will be prepended to the widget's title when displayed.
 *                                 Default `<h2 class="widgettitle">`.
 *     @type string $after_title   HTML content that will be appended to the widget's title when displayed.
 *                                 Default `</h2>`.
 * }
 */
function the_widget($widget, $instance = array(), $args = array())
{
    global $wp_widget_factory;
    $widget_obj = $wp_widget_factory->widgets[$widget];
    if (!$widget_obj instanceof WP_Widget) {
        return;
    }
    $default_args = array('before_widget' => '<div class="widget %s">', 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    $args = wp_parse_args($args, $default_args);
    $args['before_widget'] = sprintf($args['before_widget'], $widget_obj->widget_options['classname']);
    $instance = wp_parse_args($instance);
    /**
     * Fires before rendering the requested widget.
     *
     * @since 3.0.0
     *
     * @param string $widget   The widget's class name.
     * @param array  $instance The current widget instance's settings.
     * @param array  $args     An array of the widget's sidebar arguments.
     */
    do_action('the_widget', $widget, $instance, $args);
    $widget_obj->_set(-1);
    $widget_obj->widget($args, $instance);
}

WordPress Version: 4.3

/**
 * Output an arbitrary widget as a template tag.
 *
 * @since 2.8.0
 *
 * @global WP_Widget_Factory $wp_widget_factory
 *
 * @param string $widget   The widget's PHP class name (see default-widgets.php).
 * @param array  $instance Optional. The widget's instance settings. Default empty array.
 * @param array  $args {
 *     Optional. Array of arguments to configure the display of the widget.
 *
 *     @type string $before_widget HTML content that will be prepended to the widget's HTML output.
 *                                 Default `<div class="widget %s">`, where `%s` is the widget's class name.
 *     @type string $after_widget  HTML content that will be appended to the widget's HTML output.
 *                                 Default `</div>`.
 *     @type string $before_title  HTML content that will be prepended to the widget's title when displayed.
 *                                 Default `<h2 class="widgettitle">`.
 *     @type string $after_title   HTML content that will be appended to the widget's title when displayed.
 *                                 Default `</h2>`.
 * }
 */
function the_widget($widget, $instance = array(), $args = array())
{
    global $wp_widget_factory;
    $widget_obj = $wp_widget_factory->widgets[$widget];
    if (!$widget_obj instanceof WP_Widget) {
        return;
    }
    $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname']);
    $default_args = array('before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    $args = wp_parse_args($args, $default_args);
    $instance = wp_parse_args($instance);
    /**
     * Fires before rendering the requested widget.
     *
     * @since 3.0.0
     *
     * @param string $widget   The widget's class name.
     * @param array  $instance The current widget instance's settings.
     * @param array  $args     An array of the widget's sidebar arguments.
     */
    do_action('the_widget', $widget, $instance, $args);
    $widget_obj->_set(-1);
    $widget_obj->widget($args, $instance);
}

WordPress Version: 4.2

/**
 * Output an arbitrary widget as a template tag.
 *
 * @since 2.8.0
 *
 * @param string $widget   The widget's PHP class name (see default-widgets.php).
 * @param array  $instance Optional. The widget's instance settings. Default empty array.
 * @param array  $args {
 *     Optional. Array of arguments to configure the display of the widget.
 *
 *     @type string $before_widget HTML content that will be prepended to the widget's HTML output.
 *                                 Default `<div class="widget %s">`, where `%s` is the widget's class name.
 *     @type string $after_widget  HTML content that will be appended to the widget's HTML output.
 *                                 Default `</div>`.
 *     @type string $before_title  HTML content that will be prepended to the widget's title when displayed.
 *                                 Default `<h2 class="widgettitle">`.
 *     @type string $after_title   HTML content that will be appended to the widget's title when displayed.
 *                                 Default `</h2>`.
 * }
 */
function the_widget($widget, $instance = array(), $args = array())
{
    global $wp_widget_factory;
    $widget_obj = $wp_widget_factory->widgets[$widget];
    if (!$widget_obj instanceof WP_Widget) {
        return;
    }
    $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname']);
    $default_args = array('before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    $args = wp_parse_args($args, $default_args);
    $instance = wp_parse_args($instance);
    /**
     * Fires before rendering the requested widget.
     *
     * @since 3.0.0
     *
     * @param string $widget   The widget's class name.
     * @param array  $instance The current widget instance's settings.
     * @param array  $args     An array of the widget's sidebar arguments.
     */
    do_action('the_widget', $widget, $instance, $args);
    $widget_obj->_set(-1);
    $widget_obj->widget($args, $instance);
}

WordPress Version: 4.1

/**
 * Output an arbitrary widget as a template tag.
 *
 * @since 2.8.0
 *
 * @param string $widget   The widget's PHP class name (see default-widgets.php).
 * @param array  $instance Optional. The widget's instance settings. Default empty array.
 * @param array  $args {
 *     Optional. Array of arguments to configure the display of the widget.
 *
 *     @type string $before_widget HTML content that will be prepended to the widget's HTML output.
 *                                 Default `<div class="widget %s">`, where `%s` is the widget's class name.
 *     @type string $after_widget  HTML content that will be appended to the widget's HTML output.
 *                                 Default `</div>`.
 *     @type string $before_title  HTML content that will be prepended to the widget's title when displayed.
 *                                 Default `<h2 class="widgettitle">`.
 *     @type string $after_title   HTML content that will be appended to the widget's title when displayed.
 *                                 Default `</h2>`.
 * }
 */
function the_widget($widget, $instance = array(), $args = array())
{
    global $wp_widget_factory;
    $widget_obj = $wp_widget_factory->widgets[$widget];
    if (!is_a($widget_obj, 'WP_Widget')) {
        return;
    }
    $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname']);
    $default_args = array('before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    $args = wp_parse_args($args, $default_args);
    $instance = wp_parse_args($instance);
    /**
     * Fires before rendering the requested widget.
     *
     * @since 3.0.0
     *
     * @param string $widget   The widget's class name.
     * @param array  $instance The current widget instance's settings.
     * @param array  $args     An array of the widget's sidebar arguments.
     */
    do_action('the_widget', $widget, $instance, $args);
    $widget_obj->_set(-1);
    $widget_obj->widget($args, $instance);
}

WordPress Version: 3.9

/**
 * Output an arbitrary widget as a template tag.
 *
 * @since 2.8.0
 *
 * @param string $widget the widget's PHP class name (see default-widgets.php)
 * @param array $instance the widget's instance settings
 * @param array $args the widget's sidebar args
 * @return void
 **/
function the_widget($widget, $instance = array(), $args = array())
{
    global $wp_widget_factory;
    $widget_obj = $wp_widget_factory->widgets[$widget];
    if (!is_a($widget_obj, 'WP_Widget')) {
        return;
    }
    $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname']);
    $default_args = array('before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    $args = wp_parse_args($args, $default_args);
    $instance = wp_parse_args($instance);
    /**
     * Fires before rendering the requested widget.
     *
     * @since 3.0.0
     *
     * @param string $widget   The widget's class name.
     * @param array  $instance The current widget instance's settings.
     * @param array  $args     An array of the widget's sidebar arguments.
     */
    do_action('the_widget', $widget, $instance, $args);
    $widget_obj->_set(-1);
    $widget_obj->widget($args, $instance);
}

WordPress Version: 3.7

/**
 * Output an arbitrary widget as a template tag
 *
 * @since 2.8
 *
 * @param string $widget the widget's PHP class name (see default-widgets.php)
 * @param array $instance the widget's instance settings
 * @param array $args the widget's sidebar args
 * @return void
 **/
function the_widget($widget, $instance = array(), $args = array())
{
    global $wp_widget_factory;
    $widget_obj = $wp_widget_factory->widgets[$widget];
    if (!is_a($widget_obj, 'WP_Widget')) {
        return;
    }
    $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname']);
    $default_args = array('before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    $args = wp_parse_args($args, $default_args);
    $instance = wp_parse_args($instance);
    do_action('the_widget', $widget, $instance, $args);
    $widget_obj->_set(-1);
    $widget_obj->widget($args, $instance);
}