admin管理员组文章数量:1130349
I have used thumbnail like this in my wordpress theme's one template →
<?php the_post_thumbnail( 'medium' ); ?>
In the browser it is rendering like this →
<img
width="300"
height="220"
src=".jpg"
class="attachment-medium size-medium wp-post-image"
alt=""
srcset="
.jpg 300w,
.jpg 640w"
sizes="(max-width: 300px) 100vw, 300px"
>
My first question is how to put height = auto is there any function that can help us to achieve this?
such as responsive-img
In short, I am asking should I control the width through the CSS or WordPress gives some function to do this?
I have used thumbnail like this in my wordpress theme's one template →
<?php the_post_thumbnail( 'medium' ); ?>
In the browser it is rendering like this →
<img
width="300"
height="220"
src="http://example/image-300x220.jpg"
class="attachment-medium size-medium wp-post-image"
alt=""
srcset="
http://example/image-300x220.jpg 300w,
http://example/image.jpg 640w"
sizes="(max-width: 300px) 100vw, 300px"
>
My first question is how to put height = auto is there any function that can help us to achieve this?
such as responsive-img
In short, I am asking should I control the width through the CSS or WordPress gives some function to do this?
Share Improve this question edited Jun 10, 2017 at 11:39 Johansson 15.4k11 gold badges44 silver badges80 bronze badges asked Jun 10, 2017 at 11:16 WordCentWordCent 1,9646 gold badges34 silver badges60 bronze badges2 Answers
Reset to default 1If you want to remove the height value from your img URL, you can use this function:
add_filter( 'post_thumbnail_html', 'remove_thumbnail_height', 10, 5 );
function remove_thumbnail_height( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
$html = preg_replace( '/height=\"\d*\"/', "", $html );
return $html;
}
This will replace the height with an empty value. Note that you can't use Auto as a value for the height property. It won't be validated by w3 validator. However, you can set the height to auto in your CSS:
.wp-post-image {
height: auto;
}
You can use something like this,
you can use second parameter as an array of attributes as
the_post_thumbnail('medium', ['class' => 'img-responsive', 'alt' => get_the_title()]);
If you are not using bootstrap framework, in style sheet put
.img-responsive{
width: 100%;
}
I have used thumbnail like this in my wordpress theme's one template →
<?php the_post_thumbnail( 'medium' ); ?>
In the browser it is rendering like this →
<img
width="300"
height="220"
src=".jpg"
class="attachment-medium size-medium wp-post-image"
alt=""
srcset="
.jpg 300w,
.jpg 640w"
sizes="(max-width: 300px) 100vw, 300px"
>
My first question is how to put height = auto is there any function that can help us to achieve this?
such as responsive-img
In short, I am asking should I control the width through the CSS or WordPress gives some function to do this?
I have used thumbnail like this in my wordpress theme's one template →
<?php the_post_thumbnail( 'medium' ); ?>
In the browser it is rendering like this →
<img
width="300"
height="220"
src="http://example/image-300x220.jpg"
class="attachment-medium size-medium wp-post-image"
alt=""
srcset="
http://example/image-300x220.jpg 300w,
http://example/image.jpg 640w"
sizes="(max-width: 300px) 100vw, 300px"
>
My first question is how to put height = auto is there any function that can help us to achieve this?
such as responsive-img
In short, I am asking should I control the width through the CSS or WordPress gives some function to do this?
Share Improve this question edited Jun 10, 2017 at 11:39 Johansson 15.4k11 gold badges44 silver badges80 bronze badges asked Jun 10, 2017 at 11:16 WordCentWordCent 1,9646 gold badges34 silver badges60 bronze badges2 Answers
Reset to default 1If you want to remove the height value from your img URL, you can use this function:
add_filter( 'post_thumbnail_html', 'remove_thumbnail_height', 10, 5 );
function remove_thumbnail_height( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
$html = preg_replace( '/height=\"\d*\"/', "", $html );
return $html;
}
This will replace the height with an empty value. Note that you can't use Auto as a value for the height property. It won't be validated by w3 validator. However, you can set the height to auto in your CSS:
.wp-post-image {
height: auto;
}
You can use something like this,
you can use second parameter as an array of attributes as
the_post_thumbnail('medium', ['class' => 'img-responsive', 'alt' => get_the_title()]);
If you are not using bootstrap framework, in style sheet put
.img-responsive{
width: 100%;
}
本文标签: The Thumbnail aspect Ratio Issue
版权声明:本文标题:The Thumbnail aspect Ratio Issue 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749230505a2336402.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论