WordPress.org

Ready to get started?Download WordPress

Forums

Simple Responsive Images
Won't work with captioned images (2 posts)

  1. Cormac Bracken
    Member
    Posted 1 year ago #

    I can't get it to work with captioned images. WP inserts a div with a fixed width around captioned images, so we end up with a full-sized image resized to thumbnail in CSS.

    (Working with the github version)

    http://wordpress.org/extend/plugins/simple-responsive-images/

  2. Cormac Bracken
    Member
    Posted 1 year ago #

    I put this code into my regular functions.php, which stops WP from putting width attributes on the div.

    add_filter( 'img_caption_shortcode', 'rhl_remove_caption_dimensions', 10, 3 );
    
    	function rhl_remove_caption_dimensions ( $val, $attr, $content = null )
    		{
    				extract(shortcode_atts(array(
    					'id'	=> '',
    					'align'	=> '',
    					'width'	=> '',
    					'caption' => ''
    				), $attr));
    
    			if ( empty($caption) )
    			return $val;
    
    			if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
    
    			return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '">' . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
    		}

    There's still an issue with using the visual editor. Inserting an image in visual mode just inserts regular thumbnail code, not the SRI code. And switching from html editor to visual and back, the SRI code is lost.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags