WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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
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


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.