Call a Widget in pages content from admin

Home / Wordpress / Call a Widget in pages content from admin

Here its an idea how you call your widget in pages content using admin panel. If you want to call your wideget not on every page or just call or shows on single page in content area so this is very help to show you how to

Call a widget with a shortcode

. First creating a custom function for the functions.php file which would output any widget by name. After that Now in Post/Page content, you can use that widget just by referencing it by name.

function widget($atts) {
    global $wp_widget_factory;
        'widget_name' => FALSE
    ), $atts));
    $widget_name = wp_specialchars($widget_name);
    if (!is_a($wp_widget_factory->widgets[$widget_name], 'WP_Widget')):
        $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
        if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
            return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>';
            $class = $wp_class;
    the_widget($widget_name, $instance, array('widget_id'=>'arbitrary-instance-'.$id,
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '',
        'after_title' => ''
    $output = ob_get_contents();
    return $output;

Now you can use this shortcode in your page/post content area from admin.

[widget widget_name="Your_Custom_Widget"]

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *