Advertisement
Guest User

Untitled

a guest
Sep 19th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // Adding widgets with a shortcode anywhere in a page as per Digging Into WordPress
  2.  
  3. function widget($atts) {
  4.  
  5. global $wp_widget_factory;
  6.  
  7. extract(shortcode_atts(array(
  8. 'widget_name' => FALSE
  9. ), $atts));
  10.  
  11. $widget_name = wp_specialchars($widget_name);
  12.  
  13. if (!is_a($wp_widget_factory->widgets[$widget_name], 'WP_Widget')):
  14. $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
  15.  
  16. if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
  17. return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>';
  18. else:
  19. $class = $wp_class;
  20. endif;
  21. endif;
  22.  
  23. ob_start();
  24. the_widget($widget_name, $instance, array('widget_id'=>'arbitrary-instance-'.$id,
  25. 'before_widget' => '',
  26. 'after_widget' => '',
  27. 'before_title' => '',
  28. 'after_title' => ''
  29. ));
  30. $output = ob_get_contents();
  31. ob_end_clean();
  32. return $output;
  33.  
  34. }
  35. add_shortcode('widget','widget');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement