Remove thumbnail dimensions from wp_caption (2 posts)

  1. pixelkai
    Posted 2 years ago #

    i am using the following code in functions.php to get rid of the inline thumbnail dimensions generated by wordpress :)

    // Remove inline width and height added to images
    function remove_thumbnail_dimensions( $html ) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); return $html; }
    add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
    add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
    // Removes attached image sizes as well
    add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );

    this works fine excepted for images which are added through wp_captions shortcode :(

    so i thought i just add another filter
    add_filter( 'img_caption_shortcode', 'remove_thumbnail_dimensions', 10 );

    but for some reason it willl not work :(

  2. bcworkz
    Posted 2 years ago #

    Well, one problem is the parameters for 'img_caption_shortcode' are different from 'the_content', so your callback is parsing the shortcode arguments instead of content.

    Even if you correct that, the filter fires before the caption portion is actually added, and the function returns what ever your callback returns, so your callback would actually need to insert the caption content in addition to stripping out the dimensions.

Topic Closed

This topic has been closed to new replies.

About this Topic