How to resize Wordpress images to a fixed height and automatic width

I have a WP slider with costum img dimensions (fixed width and height) and I need them to scale to a fixed height of 330 pixels and automatic width. how to achieve this?

Thank you in advance!

+6
source share
4 answers

Since this was a specific Wordpress question, and I found answed, I will share it. When you add your own image size to functions.php, add 9999 to the width and hardCrop to false.

add_image_size( 'slider-thumb-alt', 9999, YOUR_FIXED_HEIGT, false); 
+21
source

First, importing them through a media manager, you can determine your own size. Otherwise, you will have to hard-code them, as @Dan Grossman mentioned. We need more information. Link to the site and slider?

0
source
 <img src="http://www.example.com/image.jpg" height="330" /> 
-1
source

It sounds like you already have a pretty decent idea of ​​what you need. Use css for this.

For instance:

 <img src="http://www.example.com/image.jpg" class="image_class"/> <style> .image_class{ width: auto; height:330px; </style> 

You want to target based on the class (and not all images using img{...} ). I have not used WP Slider, but I assume that it will add a custom class to the images in the slider. If so, just use your developer tools in a browser or view source to find out which class is being added to these images, and then create css as described above.

-3
source

Source: https://habr.com/ru/post/951158/


All Articles