I have the following text in a page. As you can see my shortcode is right at the bottom but somehow when the code runs, the output of my shortcode is inserted at the top of the page instead of following its preceding content.
<img class="alignnone" title="title_enquires" src="http://localhost/barcelona/wp-content/uploads/2011/08/title_enquires.jpg" alt="" width="589" height="77" />
<img class="alignnone" title="contact_map" src="http://localhost/barcelona/wp-content/uploads/2011/08/contact_map.jpg" alt="" width="555" height="222" />
[barcelona_address]
Here is my short code registration inside the function.php file:
<?php
add_shortcode( 'barcelona_address', 'barcelona_shortcode_handler' );
function barcelona_address_func()
{
print "<p>sdsdsds</p>";
}
function barcelona_shortcode_handler( $atts, $content=null, $code="" )
{
if (function_exists($code . "_func"))
{
call_user_func($code . "_func", $atts);
}
}
?>
And the result is:
<p>sdsdsds</p>
<img class="alignnone" title="title_enquires" src="http://localhost/barcelona/wp-content/uploads/2011/08/title_enquires.jpg" alt="" width="589" height="77" />
<img class="alignnone" title="contact_map" src="http://localhost/barcelona/wp-content/uploads/2011/08/contact_map.jpg" alt="" width="555" height="222" />
Your shortcode handler is supposed to return the output to display in place of the shortcode, not output anything itself.
http://codex.wordpress.org/Shortcode_API
You can use as alternative:
and use without return the html as string.