[resolved] removing image width and height (2 posts)

  1. derElch
    Posted 2 years ago #

    hello all together.

    i'm removing the automatic placed width and height information from images, because i want to organize the width of the images by CSS, so my theme can be responsive.

    add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
    add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
    function remove_thumbnail_dimensions( $html ) {
    	$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    	return $html;

    the problem is, this code is removing the

    [captio id="XXX"]
    ... caption text

    too and i simply dont want that. how have i to modify tis code that the caption information will still be there?

  2. derElch
    Posted 2 years ago #

    okey now i found a better script on this website:


    if i want to include this to my functions.php it wont work right.

    [caption id="XXX" width="XXX" (i know this still isnt removed)]
    < a …>< img src=”XXX” … width=”XXX” height=”XXX”/>< /a>

    I tried to modify the result img-tag to can see differences better, nothing happend, still exactly the same code like before inclunding (and the “preg_replace”).. Any idea?

Topic Closed

This topic has been closed to new replies.

About this Topic