• Resolved Shmoo

    (@macpresss)


    How do you remove the inline width & height attributes of the wp_get_attachment_image() what’s been used by the default WordPress gallery option.

    I would like to remove those two attributes from the image tag but for some reason you can remove them from almost any image tag except this gallery-thumbnail stuff that used the wp_get_attachment_image() function.

    Anybody please..

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Shmoo

    (@macpresss)

    I found something,

    This variable $hwstring should be removed from a function in the Core WordPress files but it seems there is no apply_filter() option at the button of that function.

    How can I overwrite that function?

    wp-includes/media at line 569.
    https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/media.php#L569

    Thread Starter Shmoo

    (@macpresss)

    For some reason it was wp_get_attachment_link and this filter in your functions.php file works.

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

    I came across your posts when trying to do the same. There’s an easier way. You can use wp_get_attachment_image_src to retrieve the url of the image. This returns an array, first element in the array is the url.

    So to retrieve a thumbnail I wrote:

    $src = wp_get_attachment_image_src( $attachment_ID, 'thumbnail' )[0];
    echo '<img src="'.$src.'">';

    Documentation:

    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_get_attachment_image remove width and height attribute’ is closed to new replies.