Wordpress: Omit width/height attributes from img tag

/ Published in: PHP
Save to your folder(s)

This is an example of omitting the width and height attributes from a thumbnail img tag in Wordpress. Useful if you are working on a responsive design. Use inside The Loop.

Copy this code and paste it in your HTML
  1. <?php
  2. $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
  4. if ($image) : ?>
  5. <img src="<?php echo $image[0]; ?>" alt="" />
  6. <?php endif; ?>

URL: http://wordpress.stackexchange.com/questions/29881/stop-wordpress-from-hardcoding-img-width-and-height-attributes

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.