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

I want to remove width and height properties from img tags in certain content type

Currently it show's like this

<img src="http://somesite.com/dostavka-slider-ng.jpg?itok=KDymQiug" width="938" height="300" alt="blablabla" title="blablabla" />

but I want

<img src="http://somesite.com/dostavka-slider-ng.jpg?itok=KDymQiug" alt="blablabla" title="blablabla" />
share|improve this question

3 Answers 3

up vote 3 down vote accepted

Here are some ways how to achieve this:

  • Override it with CSS !important (something like width: auto !important;);
  • Override field.tpl.php
  • Copy node.tpl.php to the theme folder and rename it, like node--MY_CONTENT_TYPE.tpl.php.

Example:

/* node--MY-CONTENT-TYPE.tpl.php */
...
<?php
$img_url = image_style_url('large', $node->field_image['und'][0]['uri'];
?>
<img src="<?php print $img_url; ?>" />
...
share|improve this answer
    
thanks, overriding with CSS was the simplest way, though maybe not the best –  Lambrusco.Newbie Dec 26 '13 at 12:44
function mytheme_preprocess_image(&$variables) {
  foreach (array('width', 'height') as $key) {
    unset($variables[$key]);
  }
}

copy this on template.php (replace "mytheme" to ur theme name) but you need to control over this because it will remove dimensions of all images in your theme.

share|improve this answer

Sorry, i can't use comment function -> need min. 50 points :-/

Do you want to display images in image field, you can use field template function. You can create .tpl file with the field name in you theme folder and edit the code.

The templates that are possible to override include:

  • field.tpl.php
  • field--field-type.tpl.php
  • field--field-name.tpl.php
  • field--content-type.tpl.php
  • field--field-name--content-type.tpl.php
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.