do_shortcode() within Admin Page

Instead of calling do_shortcode() just call the function associated with the shortcode. Example There is a shortcode named [example] and a function registered as shortcode handler: function example_shortcode( $atts = array(), $content=”” ) { extract( shortcode_atts( array ( ‘before’ => ”, ‘after’ => ”, ), $atts ) ); return $before . $content . $after; } … Read more

How to create a shortcode with 1 parameter (atts)

Here is how you should create shortcode. First you will have to define $atts item in get_userdata because $atts is an array. Also I think there is also some issues with uppercase attributes names, so you should use attribute in lower case. So instead of userID, use userid. function getUserEmail_func( $atts ) { $user_info = … Read more

Redirect function inside a Shortcode

As @Rarst explains, shortcodes normally run too late for you to redirect from inside one. They usually run on the the_content hook which is well after content is sent to the browser. If you need to redirect based on the presence of a shortcode you need to check for that shortcode before any content leaves … Read more

How to manually fix the WordPress gallery code using PHP in functions.php?

Like it was mentioned before removing the shortcode and re-adding it is not the compatible with other plugins modifying galleries so instead you use the post_gallery filter hook and the same code from the gallery_shortcode function but with your own modification for example, I’ve commented out the parts you don’t want: function fix_my_gallery_wpse43558($output, $attr) { … 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

How to use other shortcodes inside Contact form 7- forms? [closed]

There’s two ways to do what you’re wanting. First way is to add this code to functions.php of the Contact Form 7 plugin: add_filter( ‘wpcf7_form_elements’, ‘mycustom_wpcf7_form_elements’ ); function mycustom_wpcf7_form_elements( $form ) { $form = do_shortcode( $form ); return $form; } That allows you to drop shortcodes directly into CF7. Second is to add the Accordion … 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