Skip to content

Instantly share code, notes, and snippets.

@gregrickaby
Created July 17, 2014 15:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gregrickaby/4221b9455a8d4cec1f4f to your computer and use it in GitHub Desktop.
Save gregrickaby/4221b9455a8d4cec1f4f to your computer and use it in GitHub Desktop.
Prevent Wordpress from inserting an extra 10px of width to image caption shortcodes.
<?php
// DO NOT INCLUDE OPENING PHP TAG
add_filter( 'img_caption_shortcode', 'custom_remove_additional_10px_from_captions', 10, 3 );
/**
* Prevent Wordpress from inserting an extra 10px of width to image caption shortcodes.
*/
function custom_remove_additional_10px_from_captions( $val, $attr, $content = null ) {
extract( shortcode_atts( array(
'id' => '',
'align' => '',
'width' => '',
'caption' => ''
), $attr ) );
if ( 1 > ( int ) $width || empty( $caption ) ) return $val;
return '<div id="' . $id . '" class="wp-caption ' . esc_attr( $align ) . '">' . 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