WordPress.org

Ready to get started?Download WordPress

Forums

Calling widget using shortcode query poblem (2 posts)

  1. howToPlease
    Member
    Posted 11 months ago #

    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;
    }
  2. bcworkz
    Member
    Posted 11 months ago #

    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.

Reply

You must log in to post.

About this Topic