T
T
Timur Tuz2012-11-08 12:42:17
Bootstrap
Timur Tuz, 2012-11-08 12:42:17

the_post_thumbnail() How to remove sizes in img?

Salute colleagues. I made a WordPress theme based on bootstrap. Now I stick a "thumbnail" from the post into the div with the thumbnail class using the_post_thumbnail().
Problem: in ie8 the image is stretched in height. I found out that if you remove the width and height parameters in img, the glitch disappears. How to display an image without these attributes? I try:
$def_attr = array(
'width' => '',
'height' => '',
);
the_post_thumbnail('thumbnail', $def_attr);

Zero effect :( How to win?

Answer the question

In order to leave comments, you need to log in

10 answer(s)
V
Victor Victor, 2012-11-08
@TTA

And will it work?

if (has_post_thumbnail()) {
    $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');
  
    $thumb_alt = trim(strip_tags( $attachment->post_excerpt ));
    $thumb_title = trim(strip_tags( $attachment->post_title ));
  
    echo '<img src="'.$thumb[0].'" alt="'.$thumb_alt.'" title="'.$thumb_title.'" />';
}

I
Igor, 2014-08-30
@bybelov

You can also insert into functions.php

function true_thumbnail_url_only( $html ){
  return preg_replace('#.*src="([^\"]+)".*#', '\1', $html );
}
add_filter('post_thumbnail_html', 'true_thumbnail_url_only', 10, 5);

As a result, when called,
only a link to the thumbnail will be displayed.

N
Nikolai Vasilchuk, 2012-11-08
@Anonym

If you know the width and height of the image, it's better to specify them.
Beat IE8 with CSS.

S
startsevdenis, 2012-11-08
@startsevdenis

If I remember correctly, it will not work without them, because they are set depending on the first argument, and the second argument can be set just class, title, etc.
So as noted above, try to win with css.

T
Timur Tuz, 2012-11-08
@TTA

Made:

$def_attr = array('class' => 'fixtmb',);
the_post_thumbnail('thumbnail', $def_attr);

Zero effect

4
432750, 2012-11-08
@432750

can they be removed? Thumb types are defined in functions.php. name of the type and its dimensions,?

E
Eduard Valeev, 2013-08-24
@Adward

Can you plz tell me
how to display a thumbnail, knowing the post ID?
I want to display multiple thumbnails for certain posts.

A
Aligatro, 2014-02-11
@Aligatro

Gentlemen, please tell me, is it possible to optimize this query somehow?

$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');

otherwise this joy generates a cloud of requests. Or the thumbnail output for each post will still generate 1 request at a time.

A
Aligatro, 2014-02-11
@Aligatro

Problem solved by replacing

wp_get_attachment_image_src . 'на' . the_post_thumbnail
, now for each post on the page, a separate request is not generated. The performance remains the same.

D
DMon777, 2017-02-10
@DMon777

To remove the width and height attributes from the_post_thumbnail(), you need to insert the following code in functions.php -
add_filter ('post_thumbnail_html','no_width_height_html',10,1);
function no_width_height_html($html){
$pos = strpos($html,'src');
$html='

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question