get_shortcode_regex() only matches first shortcode

From PHP docs (emphasis mine): preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match. preg_match_all() on the contrary will continue until it reaches the end of subject.

Get the content inside shortcode and apply external function to it?

The following adds the shortcode [my_t_shortcode], which accepts an attribute ‘lang’, and applys the above mentioned function to the content. //Add shortcodes add_shortcode( ‘my_t_shortcode’, ‘wpse41477_shortcode_handler’ ); //It’s good practise to make sure your functions are prefixed by something unique function wpse41477_shortcode_handler( $atts, $content = null ) { //This will extract ‘lang’ attribute as $lang. You … Read more

Stop auto formatting in shortcodes

You can postpone the wp_autop filter which is responsible for wrapping elements in P tags till after shortcodes are rendered: remove_filter( ‘the_content’, ‘wpautop’ ); add_filter( ‘the_content’, ‘wpautop’ , 12);

Remove action from shortcode

I do not want to removing and re-adding shortcode, because there is huge function beyond it. This might not answer your question, but the size of the shortcode function itself does not make much of a difference for removing and re-adding. Short or long functions take the same time here. So don’t hinder yourself removing … Read more

Caption shortcodes not including caption as attribute

Find the line /* Remove in-line styling in function.php. Comment out: /* add_shortcode(‘wp_caption’, ‘fixed_img_caption_shortcode’); add_shortcode(‘caption’, ‘fixed_img_caption_shortcode’); function fixed_img_caption_shortcode($attr, $content = null) { // Allow plugins/themes to override the default caption template. $output = apply_filters(‘img_caption_shortcode’, ”, $attr, $content); if ( $output != ” ) return $output; extract(shortcode_atts(array( ‘id’=> ”, ‘align’ => ‘alignnone’, ‘width’ => ”, ‘caption’ … Read more

Check if post has gallery images/media

No Need for SQL queries in the template. function wpse_72594_get_attachments( $id, $mime=”” ) { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => $mime, ‘post_parent’ => $id ); $attachments = get_posts($args); if ($attachments) return $attachments; return false; } Then call the function like this (300 is the post ID): wpse_72594_get_attachments(300), grabs all attachments wpse_72594_get_attachments(300, ‘image’ ), … Read more