Posted By

gd6d on 04/13/10


Tagged

wordpress widget shortcode


Versions (?)

Call a Widget with a Shortcode


 / Published in: PHP
 

URL: http://digwp.com/2010/04/call-widget-with-shortcode/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+DiggingIntoWordpress+%28Digging+Into+WordPress%29

  1. function widget($atts) {
  2.  
  3. global $wp_widget_factory;
  4.  
  5. extract(shortcode_atts(array(
  6. 'widget_name' => FALSE
  7. ), $atts));
  8.  
  9. $widget_name = wp_specialchars($widget_name);
  10.  
  11. if (!is_a($wp_widget_factory->widgets[$widget_name], 'WP_Widget')):
  12. $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
  13.  
  14. if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
  15. return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>';
  16. else:
  17. $class = $wp_class;
  18. endif;
  19. endif;
  20.  
  21. the_widget($widget_name, $instance, array('widget_id'=>'arbitrary-instance-'.$id,
  22. 'before_widget' => '',
  23. 'after_widget' => '',
  24. 'before_title' => '',
  25. 'after_title' => ''
  26. ));
  27. $output = ob_get_contents();
  28. return $output;
  29.  
  30. }
  31. add_shortcode('widget','widget');

Report this snippet  

You need to login to post a comment.