Skip to content

Instantly share code, notes, and snippets.

@thierrypigot
Created May 28, 2015 08:39
Show Gist options
  • Save thierrypigot/44305728554375e18ffb to your computer and use it in GitHub Desktop.
Save thierrypigot/44305728554375e18ffb to your computer and use it in GitHub Desktop.
WordPress : use widget inside content page
<?php
// [widget type="WP_Widget_Archives"]
add_shortcode( 'widget', 'tp_widget_shortcode' );
function tp_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