Why is my shortcode content showing before other content?

Shortcode Showing Before Other Content

If you have created a shortcode but it’s showing up before the other content on your WordPress site, it might be because you used an “echo” instead of a “return” in your callback function.

add_shortcode()

Incorrect:


add_shortcode( 'follow-us', 'myshortcode' );

function myshortcode( $atts ) {

echo '<br />Follow us on Facebook!';

}

Correct:


add_shortcode( 'follow-us', 'myshortcode' );

function myshortcode( $atts ) {

return '<br />Follow us on Facebook!';

}

Was this post helpful?