Shortcode always displaying at the top of the page

You can buffer the output like this:

ob_start();
include(locate_template('loop-'.$module.'.php'));
return ob_get_clean();

EDIT. I tried this, worked fine.

function friendly_loop_shortcode( $atts, $content = null ) {
     extract( shortcode_atts( array(
         'category' => '',
         'module' => ''
     ), $atts ) );

     ob_start();
     include(locate_template('loop-'.$module.'.php'));
     $output = ob_get_clean();
     //print $output; // debug
     return $output;
}

if (!is_admin()) {
     add_shortcode('test', 'friendly_loop_shortcode' );
}

Leave a Comment