Created
July 17, 2014 15:39
-
-
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.
This file contains hidden or 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 | |
// 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