Support » Plugins » Hacks » Calling widget using shortcode query poblem

  • I am calling a widget using shortcode,
    everything is wordking except when I passs a widget option as a query then it only accepts title.

    Like
    [widget name="WP_Widget_Categories"]title=Category&dropdown=1&count=1&hierarchical=1[/widget]

    Now when this shortcode output then it shows my title query but no action for other three query. I tried this with all widget, same problem.

    Please check if my query format is mistaken.

    and here is my shortcode function

    add_shortcode('widget','widget');
    function ra_widget($atts, $content) {
    	// Configure defaults and extract the attributes into variables
    	extract( shortcode_atts(
    		array(
    			'name'  => ''
    		),
    		$atts
    	));
    
    	ob_start();
    	the_widget($name, $content, 'before_widget=<div class="post-widget">&after_widget=</div>&before_title=<h3>&after_title=</h3>');
    	$output = ob_get_clean();
    
    	return $output;
    }

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    It appears shortcode content is run through htmlentities() so that the ‘&’ parameter separator gets converted to # 038; (without the space). Thus the string parser of the_widget() fails to parse any arguments after any ‘&’ characters since that character is no longer found.

    You can undo this with
    $content = html_entity_decode($content);
    in your shortcode callback before the call to the_widget(), after which all your parameters should be parsed correctly.

Viewing 1 replies (of 1 total)
  • The topic ‘Calling widget using shortcode query poblem’ is closed to new replies.