public
Last active

WordPress responsive captions

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<?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 );

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.