Created
December 12, 2012 10:33
-
-
Save sheabunge/4266741 to your computer and use it in GitHub Desktop.
Easily insert any WordPress sidebar widget into a post or page using a shortcode.
http://wp.smashingmagazine.com/2012/12/11/inserting-widgets-with-shortcodes/
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 | |
/** | |
* Plugin Name: Widget Shortcode | |
* Plugin URI: http://wp.smashingmagazine.com/2012/12/11/inserting-widgets-with-shortcodes/ | |
* Description: Easily insert any WordPress sidebar widget into a post or page using a shortcode. | |
* Author: Smashing Magazine | |
* Author URI: http://www.smashingmagazine.com | |
* Version: 1.0 | |
*/ | |
add_shortcode( 'widget', 'my_widget_shortcode' ); | |
function my_widget_shortcode( $atts ) { | |
// Configure defaults and extract the attributes into variables | |
extract( shortcode_atts( | |
array( | |
'type' => '', | |
'title' => '', | |
'scheme' => 'light' | |
), | |
$atts | |
)); | |
$args = array( | |
'before_widget' => '<div class="box widget scheme-' . $scheme . ' ">', | |
'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