Skip to content

Instantly share code, notes, and snippets.

@stas
Created February 17, 2012 15:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stas/1854115 to your computer and use it in GitHub Desktop.
diff --git wp-includes/media.php wp-includes/media.php
index e3b9008..757999d 100644
--- wp-includes/media.php
+++ wp-includes/media.php
@@ -725,6 +725,17 @@ add_shortcode('caption', 'img_caption_shortcode');
*/
function img_caption_shortcode($attr, $content = null) {
+ // Backwards compatibility for < v3.4.0 shortcode
+ if ( !isset( $attr['caption'] ) ) {
+ // Searches and returns as caption all text except image tag (with link or not)
+ // The image tag (with link or not) is left inside $content
+ $count = preg_match( '~((?i:<a.+<img.+</a|<img.+)>)(.*)~i', $content, $matches );
+ if ( $count > 0 ) {
+ $content = $matches[1];
+ $attr['caption'] = $matches[2];
+ }
+ }
+
// Allow plugins/themes to override the default caption template.
$output = apply_filters('img_caption_shortcode', '', $attr, $content);
if ( $output != '' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment