Skip to content

Instantly share code, notes, and snippets.

@jentanbernardus
Forked from DrewAPicture/gist:2243601
Created June 30, 2012 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jentanbernardus/3023022 to your computer and use it in GitHub Desktop.
Save jentanbernardus/3023022 to your computer and use it in GitHub Desktop.
WordPress responsive captions
add_filter( 'img_caption_shortcode', 'dap_responsive_img_caption_filter', 10, 3 );
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;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="max-width: 100% !important; height: auto; width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment