Viewing 1 replies (of 1 total)
  • Thread Starter Ulcecurce

    (@ulcecurce)

    So, i found the solution. Just add this code to theme’s functions.php file:

    // this creates a widget shortcode functionality (use with [widget widget_name="WCAPF_Active_Filters_Widget"] shortcode)
    
    function widget($atts) {
    
    global $wp_widget_factory;
    
    extract(shortcode_atts(array(
    '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>';
    else:
    $class = $wp_class;
    endif;
    endif;
    
    ob_start();
    the_widget($widget_name, $instance, array('widget_id'=>'arbitrary-instance-'.$id,
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '',
    'after_title' => ''
    ));
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
    
    }
    add_shortcode('widget','widget');

    And after that we can use shortcodes like [widget widget_name=”WCAPF_Active_Filters_Widget”] or [widget widget_name=”WCAPF_Category_Filter_Widget”] or [widget widget_name=”WCAPF_Price_Filter_Widget”] in our pages.

Viewing 1 replies (of 1 total)
  • The topic ‘Inserting filter with shortcode (or php code)’ is closed to new replies.