Shortcode output at top of page content in WordPress

Jun 17, 2014 code, wordpress

Come across a shortcode glitch a while back when I was building custom interface for a client site. The shortcode’s output was displaying at the top of the page content, no matter where I dropped the shortcode. Searched around for quite a bit until I found the fix. Hopefully you will find this blog post to save you time on those others that didn’t help me much.

Turns out the fix was ob_start();

function your_shortcode() {
ob_start();
//fancy code goes here aka functionality of shortcode
return ob_get_clean();
}
add_shortcode('admincode','your_shortcode');