Created
May 28, 2015 08:39
-
-
Save thierrypigot/44305728554375e18ffb to your computer and use it in GitHub Desktop.
WordPress : use widget inside content page
This file contains hidden or 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 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