Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress: allows you to insert a widget into any content area using a shortcode
<?php
/**
* Widget Shortcode
* - allows you to insert a widget into any content area using a shortcode
* - credit: http://wp.smashingmagazine.com/2012/12/11/inserting-widgets-with-shortcodes/
* - read the comments on the Smashing Magazine article for pros and cons of this function
*/
add_shortcode( 'mcw_widget', function ( $atts ) {
// configure defaults and extract the attributes into variables
extract( shortcode_atts(
array(
'type' => '',
'title' => '',
'show_title' => false,
'count' => 0,
'image' => false,
),
$atts
));
$args = array(
'before_widget' => '<div class="box widget">',
'after_widget' => '</div>',
'before_title' => '<div class="widget-title">',
'after_title' => '</div>',
);
ob_start();
the_widget( $type, $atts, $args );
$output = ob_get_clean();
return $output;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.