Shortcode to Use a WordPress widget in Page Content
Written on July 18, 2016
add_shortcode('do-widget',function($atts,$content){ shortcode_atts(array( 'widget' => null ),$atts); if( $atts['widget'] == null ) return 'No widget provided.'; $widget = $atts['widget']; unset($atts['widget']); $widget_instance_args = http_build_query($atts); ob_start(); the_widget($widget,$widget_instance_args); $widget_output = ob_get_contents(); ob_end_clean(); return $widget_output; } );