Hi I have created a plugin that places a Google Translator into a text widget in Wordpress. I have setup shortcode to do this - and the shortcode seems to be outputting the correct HTML, except that the HTML is not showing up INSIDE of the text widget as it should.

Here is my plugin code: http://pastebin.com/BMbnEqAW

Here is the page: http://www.richmindonline.com/test/

When I do a "View Page Source" from Firefox - I am noticing that the translator code is appearing BEFORE the text widget. So even though my shortcode is located inside of the text widget, the code shows up just above the text widget itself and is not wrapped inside of id="text-widget".

There are not stray div tags that I can find either. Are there any common problems with using javascript or shortcodes in a text widget that I should account for in my plugin?

  • I think a float is working here in your plugin without clearing float. Use Firebug instead of page source for a better code view. Then try to find out the exact colliding code. Then we'll be on the specific portion. :) Jan 19, 2013 at 10:35
  • Shortcodes are not echo'ed, they are return'ed. Whenever a WP function/ality doesn't behave, check the documentation first.
    – brasofilo
    Jan 19, 2013 at 13:47
  • Wow... That is an old-school widget. You should really look into the Widget API
    – s_ha_dum
    Jan 19, 2013 at 15:53
  • Brasofilo, please add this as an answer and I will accept. I just used your solution for two different sets of functions in my plugin, and the problem was solved. Thanks.
    – Rob Myrick
    Jan 19, 2013 at 18:30

1 Answer 1


That's a common mistake, Shortcodes should return values and not echo.

Remember, the Codex is your Friend ;)


The return value of a shortcode handler function is inserted into the post content output in place of the shortcode macro. Remember to use return and not echo - anything that is echoed will be output to the browser, but it won't appear in the correct place on the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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