WordPress.org

Ready to get started?Download WordPress

Forums

Remove thumbnail dimensions from wp_caption (2 posts)

  1. pixelkai
    Member
    Posted 6 months 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
    Member
    Posted 6 months 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.

Reply

You must log in to post.

About this Topic