How to detect if a Shortcode is being called on a page?

I have sometimes wondered the same thing – whether wp maybe checked on save and kept a register etc I had a quick look at the code, and it seems not. There is however a global $shortcode_tags, and wp has this function function get_shortcode_regex() { global $shortcode_tags; $tagnames = array_keys($shortcode_tags); $tagregexp = join( ‘|’, array_map(‘preg_quote’, … Read more

Organizing shortcodes. How to display all of them and their attributes?

Inspect the global variable $shortcode_tags: print ‘<pre>’ . htmlspecialchars( print_r( $GLOBALS[‘shortcode_tags’], TRUE ) ) . ‘</pre>’; Output: Array ( => img_caption_shortcode => img_caption_shortcode => gallery_shortcode => __return_false [contactform] => Array ( [0] => T5_Contact_Form Object ( [debug:protected] => [base_name:protected] => t5-contact-form/t5-contact-form.php [prefix:protected] => t5c [address:protected] => [nonce_name:protected] => t5_contact_form_nonce [hidden_field:protected] => t5_no_fill [option_name:protected] => t5c_default_address … Read more

Always use for post images

You can try the image_send_to_editor filter: /** * Wrap the inserted image html with <figure> * if the theme supports html5 and the current image has no caption: */ add_filter( ‘image_send_to_editor’, function( $html, $id, $caption, $title, $align, $url, $size, $alt ) { if( current_theme_supports( ‘html5’ ) && ! $caption ) $html = sprintf( ‘<figure>%s</figure>’, $html … Read more

enqueue script for specific shortcode

wp_enqueue_script is not going to work in a shortcode, this is because of the loading order. You could use wp_register_script and then you could wp_enqueue_script in you shortcode function like this example: // Front-end function front_end_scripts() { wp_register_script( ‘example-js’, ‘//example.com/shared-web/js/example.js’, array(), null, true ); } add_action( ‘wp_enqueue_scripts’, ‘front_end_scripts’ ); Then you use this in your … Read more

Shortcode to insert

Best solution for what you want to accomplish which is essentially to make the next page feature more user friendly for your authors is to add a TinyMCE button that will do this for you. This may be a bit complicated so hold your hat. To avoid this answer being the length of a thesis, … Read more

Are shortcodes case-sensitive?

Short Answer Yes, shortcodes are case sensitive Longer Answer It’s really easy to build a test case for this and see. <?php add_shortcode(‘sOme_ShOrTcOdE’, ‘wpse102375_shortcode’); function wpse102375_shortcode($args, $content=null) { return ‘yep’; } Longest Answer Read the source. The “magic” with shortcodes happens in do_shortcode, so let’s take a look at that. <?php // wp-includes/shortcode.php function do_shortcode($content) … Read more

Shortcode output always showing at top of page

I think your problem is with the $output = include …. statement. include() returns true or false based whether it was successful – not the content of the file being included. Use output buffering to get the content. function service_shortcode_index() { global $content; ob_start(); include ( TEMPLATEPATH . ‘/service.php’ ); $output = ob_get_clean(); return $output; … Read more

Nested Shortcode Detection

From: http://codex.wordpress.org/Shortcode_API#Limitations The shortcode parser correctly deals with nested shortcode macros, provided their handler functions support it by recursively calling do_shortcode() It will not let you nest the same shortcode inside another though: However the parser will fail if a shortcode macro is used to enclose another macro of the same name Assuming you won’t … Read more

List of all inbuilt WordPress shortcodes

You can actually list all of the available shortcodes for your WordPress installation by using the following code: <?php global $shortcode_tags; echo ‘<pre>’; print_r($shortcode_tags); echo ‘</pre>’; ?> It will show the main WordPress shortcodes plus any shortcodes for installed plugins which can be handy too!