Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I found this great solution: Stop wordpress from hardcoding img width and height attributes

But I was wondering if I could do it only in one specific case and not in all the site because it messes up other stuff. This would be the case:

<?php echo wp_get_attachment_image($attachment->ID, 'six', false, $default_attr); ?>

Removing only height but not width in all the site would also work.

share|improve this question
1  
Can you explain why you want to do this? Understanding your need may open up other solutions. –  Stephen Nov 1 '12 at 23:17

2 Answers 2

You can also get the data for width and hight of a image.

$src = wp_get_attachment_image_src( $attachment_id, 'full' );
var_dump($src);

the var_dump output like this:

array
  0 => string 'http://example.com/wp-content/uploads/2009/08/DSC00261.JPG' (length=63)
  1 => int 1632
  2 => int 1224
  3 => boolean false

The results mean:

$src[0] => url
$src[1] => width
$src[2] => height
$src[3] => icon
share|improve this answer

This worked for me.

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

and then change

wp_get_attachment_image_src( $attachment_id, 'full' );

to

remove_width_and_height_attribute(wp_get_attachment_image_src( $attachment_id, 'full' ));
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.