how to show the syntax of a shortcode
If you use double brackets, WordPress will not execute the shortcode but just display it with single brackets. So becomes in your post.
If you use double brackets, WordPress will not execute the shortcode but just display it with single brackets. So becomes in your post.
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
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
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
To display a shortcode instead of rendering it you have two options: Write [[shortcode]]. WordPress will show this as [shortcode]. Escape the [, write it as as [ or [.
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
I don’t know of an official escape syntax for shortcodes and there likely isn’t one. When wordpress parses for shortcodes it looks for [ and ]. If you want to use square brackets within a shortcode, using the respective html ASCII entities escapes them. I.e. replacing [ by [ and ] by ]. WordPress will … Read more
shortcode_atts() works like array_merge(): It merges the second list of arguments into the first one. The difference is: It merges only keys present in the first argument ($default). extract() then takes the array keys, sets these as variable names and their values as variable values. ‘w’ => ‘500’ in your example becomes $w = ‘500’. … Read more
Based on my own experience, I’ve used a combination of method 1 & 2 – the architecture and footer scripts of 1, and the ‘look-ahead’ technique of 2. For the look-ahead though, I use regex in place of stripos; personal preference, faster, and can check for ‘malformed’ shortcode; preg_match( ‘#\[ *shortcode([^\]])*\]#i’, $content ); If you’re … Read more
I found an other way that works well for me: When initializing the plugin, do not enqueue your scripts and styles, but register them with wp_register_style and wp_register_script. Next you can load the script/style on demand. For example when you render a shortcode with wp_enqueue_style(“your_style”) and wp_enqueue_script(“your_script”). Here is an example plugin using this method … Read more