Support » Plugins » Hacks » Remove thumbnail dimensions from wp_caption

  • 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 🙁

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    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.

Viewing 1 replies (of 1 total)
  • The topic ‘Remove thumbnail dimensions from wp_caption’ is closed to new replies.