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.
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!';
}