Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Commit

Permalink
Remove default inline style of wp-caption
Browse files Browse the repository at this point in the history
  • Loading branch information
olefredrik committed Mar 13, 2014
1 parent d23e923 commit 4059738
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions library/cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ function gallery_style($css) {
* ----------------------------------------------------------------------------
*/


// Remove default inline style of wp-caption
add_shortcode('wp_caption', 'fixed_img_caption_shortcode');
add_shortcode('caption', 'fixed_img_caption_shortcode');
function fixed_img_caption_shortcode($attr, $content = null) {
if ( ! isset( $attr['caption'] ) ) {
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
$content = $matches[1];
$attr['caption'] = trim( $matches[2] );
}
}
$output = apply_filters('img_caption_shortcode', '', $attr, $content);
if ( $output != '' )
return $output;
extract(shortcode_atts(array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $content;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . $width . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}


// Clean the output of attributes of images in editor
function image_tag_class($class, $id, $align, $size) {
$align = 'align' . esc_attr($align);
Expand Down

5 comments on commit 4059738

@carlotrimarchi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this code I still am experiencing a problem with captioned images. When I insert a caption, then I see the image in full width. I fixed it by removing the style="width: '. $width . 'px part from line 146. Don't know if it's ok to do it like this, but to me it seems it's working.

@jazbek
Copy link

@jazbek jazbek commented on 4059738 Jun 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, isn't the point of this commit to remove the inline styles?

@jazbek
Copy link

@jazbek jazbek commented on 4059738 Jun 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this breaks the img_unautop filter.

@studiobovenkamer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep still seeing the inline CSS. I don't know why this is default WP behaviour.

@robbymilo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed responsive issues by changing style="width: ' . $width . 'px" to style="max-width: ' . $width . 'px".

Please sign in to comment.