the_widget()
Output an arbitrary widget as a template tag.
Hooks from the function
Return
null
. Nothing (null).
Usage
the_widget( $widget, $instance, $args );
- $widget(string) (required)
- The widget's PHP class name (see class-wp-widget.php).
- $instance(array)
- The widget's instance settings.
Default: empty array - $args(array)
Array of arguments to configure the display of the widget.
Default: array()
-
before_widget(string)
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 -
after_widget(string)
HTML content that will be appended to the widget's HTML output.
Default: </div> -
before_title(string)
HTML content that will be prepended to the widget's title when displayed.
Default: <h2 class="widgettitle"> - after_title(string)
HTML content that will be appended to the widget's title when displayed.
Default: </h2>
-
Examples
#1 Demo
Show widget with default settings:
<?php the_widget( 'WP_Widget_Categories' ); ?>
Show settings widget:
<?php the_widget( 'WP_Widget_Categories', 'dropdown=1&count=1' ); ?>
Show widget with custom parameters:
<?php $instance = array( 'dropdown' => 1, 'count' => 1, ); $args = array( 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title">', 'after_title' => '</div>' ); the_widget( 'WP_Widget_Categories', $instance, $args ); ?>
Notes
- Global. WP_Widget_Factory. $wp_widget_factory
Changelog
Since 2.8.0 | Introduced. |