I develop my plugin with this code :
function my_function( $atts ) {
some code
}
add_shortcode( 'myfunction_shortcode', 'my_function' );
I need to use my shortcode on my page or post, when I used it output code shown on top of my page.
I develop my plugin with this code :
function my_function( $atts ) {
some code
}
add_shortcode( 'myfunction_shortcode', 'my_function' );
I need to use my shortcode on my page or post, when I used it output code shown on top of my page.
This is most likely due to the way your shortcode is constructed. PHP scripts are run on the server before (as) the HTML is generated.
Try buffering your shortcode ouput like this:
function my_function( $atts ) {
ob_start();
// do some stuff
$code_output = ob_get_contents();
ob_end_clean();
return $code_output;
}
More info: https://secure.php.net/manual/en/book.outcontrol.php