Last active
April 7, 2017 21:25
-
-
Save donnamcmaster/51369db6fc96bf323112068a25026ae2 to your computer and use it in GitHub Desktop.
WordPress: allows you to insert a widget into any content area using a shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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