Usage
[widget widget_name instances]
Parameters
widget_name
(Required) (String) The name of the widget to call
Default: None
instances
(Optional) (String) Attributes for the widget
Default: None
Parameter Notes
The instances
parameter is actually a series of attribute=”value” parameters. The attribute should be the parameter name from the widget. See examples for more help.
Examples
Call a widget without using instances
[widget widget_name="nebula_login_form"]
Call a widget with custom settings
[widget widget_name="nebula_linked_image" image="http://placehold.it/300x300" url="http://google.com"]
Call this function from a PHP template
<?php echo do_shortcode('[widget widget_name="nebula_linked_image" image="http://placehold.it/300x300" url="http://google.com"]'); ?>
Call a widget directly via PHP without this function
<?php the_widget('nebula_linked_image', array('image' => 'http://placehold.it/300x300', 'url' => 'http://google.com')); ?>
Source File
Located in /libs/Shortcodes.php on line 112.
public function widget($atts){ global $wp_widget_factory; //Get widget fields $instance = array(); foreach ( $atts as $attribute => $value ){ if ( $attribute !== 'widget_name' ){ $instance[$attribute] = $value; } } extract(shortcode_atts(array( 'widget_name' => false, ), $atts)); ob_start(); //Call the widget directly via PHP: https://codex.wordpress.org/Template_Tags/the_widget the_widget(esc_html($widget_name), $instance, array( 'widget_id' => 'arbitrary-instance-' . random_int(100000, 999999), //PHP 7.4 use numeric separators here 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '' )); $output = ob_get_contents(); ob_end_clean(); return $output; }
Override
To override or disable this shortcode, use add_shortcode()
to declare the shortcode first.