Custom shortcode being executed when saving page in wp-admin

Shortcodes must return, not echo or print their output. As the Codex entry for add_shortcode() explains: Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. … Read more

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’ … Read more

Pass boolean value in shortcode

Is easy to use 0 and 1 values and then typecasting inside the function: [shortcode boolean_attribute=”1″] or [shortcode boolean_attribute=”0″] but if you want you can also strictly check for ‘false’ and assign it to boolean, in this way you can also use: [shortcode boolean_attribute=”false”] or [shortcode boolean_attribute=”true”] Then: add_shortcode( ‘shortcode’, ‘shortcode_cb’ ); function shortcode_cb( $atts … Read more