Last active
October 14, 2016 08:11
-
-
Save joemcgill/4636708 to your computer and use it in GitHub Desktop.
Removes the silly 10px margin from caption based images in WP (H/T Justin Adie)
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
/** | |
* Description: removes the silly 10px margin from caption based images | |
* Author: Justin Adie | |
* Version: 0.1.0 | |
* Author URI: http://rathercurious.net | |
*/ | |
class fixImageMargins{ | |
public $xs = 0; //change this to change the amount of extra spacing | |
public function __construct(){ | |
add_filter('img_caption_shortcode', array(&$this, 'fixme'), 10, 3); | |
} | |
public function fixme($x=null, $attr, $content){ | |
extract(shortcode_atts(array( | |
'id' => '', | |
'align' => 'alignnone', | |
'width' => '', | |
'caption' => '' | |
), $attr)); | |
if ( 1 > (int) $width || empty($caption) ) { | |
return $content; | |
} | |
if ( $id ) $id = 'id="' . $id . '" '; | |
return '<div ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . ((int) $width + $this->xs) . 'px">' | |
. $content . '<p class="wp-caption-text">' . $caption . '</p></div>'; | |
} | |
} | |
$fixImageMargins = new fixImageMargins(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment