I have my shortcode system set up fairly normally, like so:
//[carouselle]
function carouselle_func( $atts ){
return "foo and bar";
}
add_shortcode( 'carouselle', 'carouselle_func' );
But when I do the same thing but with an echo statement instead of a return…
//[carouselle]
function carouselle_func( $atts ){
echo "foo and bar";
}
add_shortcode( 'carouselle', 'carouselle_func' );
it displays “foo and bar” inside the post and also immediately the body tag.
I checked my header and I’m not calling the_content anywhere near there. So, is this because I’m doing an echo? I was hoping to eventualy do something like this:
//[carouselle]
function carouselle_func( $atts ){
?>
<h1>Some HTML Stuff</h1>
<?php
}
add_shortcode( 'carouselle', 'carouselle_func' );
But when this code executes, what happens is
Some HTML stuff
gets displayed near the top of my theme and also in the content of the post. Bizarre, or is this not even allowed?
Shortcode functions are supposed to “return” the value, not echo it:
http://codex.wordpress.org/Shortcode_API