Skip to content

Instantly share code, notes, and snippets.

@DrewAPicture
Last active October 2, 2015 12:28
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save DrewAPicture/2243601 to your computer and use it in GitHub Desktop.
Save DrewAPicture/2243601 to your computer and use it in GitHub Desktop.
WordPress responsive captions
<?php
function dap_responsive_img_caption_filter( $val, $attr, $content = null ) {
extract( shortcode_atts( array(
'id' => '',
'align' => '',
'width' => '',
'caption' => ''
), $attr
) );
if ( 1 > (int) $width || empty( $caption ) )
return $val;
$new_caption = sprintf( '<div id="%1$s" class="wp-caption %2$s" style="max-width:100% !mportant;height:auto;width:%3$dpx;">%4$s<p class="wp-caption-text">%5$s</p></div>',
esc_attr( $id ),
esc_attr( $align ),
( 10 + (int) $width ),
do_shortcode( $content ),
$caption
);
return $new_caption;
}
add_filter( 'img_caption_shortcode', 'dap_responsive_img_caption_filter', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment