Answer the question
In order to leave comments, you need to log in
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
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.'" />';
}
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);
If you know the width and height of the image, it's better to specify them.
Beat IE8 with CSS.
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.
Made:
$def_attr = array('class' => 'fixtmb',);
the_post_thumbnail('thumbnail', $def_attr);
can they be removed? Thumb types are defined in functions.php. name of the type and its dimensions,?
Can you plz tell me
how to display a thumbnail, knowing the post ID?
I want to display multiple thumbnails for certain posts.
Gentlemen, please tell me, is it possible to optimize this query somehow?
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');
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.
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 questionAsk a Question
731 491 924 answers to any question