Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

OK, I've had a problem with echoes in my last shortcodem, but everything works fine now.

But I have another one:

function myWidget_shortcode( $atts ) {
        extract( shortcode_atts( array(
        'title' => 'My Widget',
        'value' => '5',
        ), $atts ) );

        return the_widget(myWidget,'title='.$title.'&value='.$value);
}

add_shortcode('myWidget', 'myWidget_shortcode'); 

Can you tell me wy this shortcode always displays first on pages? There's no echo etc., all the data is being returned...

[found the answer - edit]

This resolves the problem:

ob_start();    
the_widget(popularPosts,'title='.$title.'&number='.$number);
return ob_get_clean();

Anyways I don't understand why it's always first in this case. Because the_widget is a function itself and echoes something? :>

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Yes, look at the widget() method in your MyWidget class. Does it echo? Most likely it does, because that's how widgets are normally written. In fact, I'd be surprised to see a widget that didn't echo output in its widget() method.

And when you call the_widget(), it fetches an instance of the widget you ask for, and calls $widget_obj->widget($args, $instance);. So it echos, and doesn't return anything.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.