Last active
October 2, 2015 12:28
-
-
Save DrewAPicture/2243601 to your computer and use it in GitHub Desktop.
WordPress responsive captions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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