Background:
I am using WordPress
posts for Newsletter
. I am importing the posts through an api
and use them in a Newsletter
tool to send them out. I am downsizing the featured image before feeding to the Newsletter tool. But now I am facing some troubles, sometimes I have High resolution post content images.
Issue:
I need to resize those inner images of post content but without using any css
and html
image tags attributes
as I am using them for the Newsletter purpose.
I know that how to handle that with html
and css
tags like bellow;
<img class="wp-image-290893 aligncenter lazyloaded" src=".jpg" alt="" sizes="(max-width: 1000px) 100vw, 1000px" srcset=".jpg 1985w, .jpg 158w, .jpg 768w, .jpg 1024w, .jpg 237w" data-ll-status="loaded" width="1000" height="631">
My question is whether there is anyway to downsize these images if those are exceeding certain width(perhaps 800px) in real. This optimization helps to save lot of bandwidth as per my calculation.
Any help would be really appreciating.
Background:
I am using WordPress
posts for Newsletter
. I am importing the posts through an api
and use them in a Newsletter
tool to send them out. I am downsizing the featured image before feeding to the Newsletter tool. But now I am facing some troubles, sometimes I have High resolution post content images.
Issue:
I need to resize those inner images of post content but without using any css
and html
image tags attributes
as I am using them for the Newsletter purpose.
I know that how to handle that with html
and css
tags like bellow;
<img class="wp-image-290893 aligncenter lazyloaded" src="https://fcam.b-cdn.net/blog/wp-content/uploads/Finnair_A350_Business_Class_Seat_Champagne_Glass.jpg" alt="" sizes="(max-width: 1000px) 100vw, 1000px" srcset="https://fcam.b-cdn.net/blog/wp-content/uploads/Finnair_A350_Business_Class_Seat_Champagne_Glass.jpg 1985w, https://fcam.b-cdn.net/blog/wp-content/uploads/Finnair_A350_Business_Class_Seat_Champagne_Glass-158x100.jpg 158w, https://fcam.b-cdn.net/blog/wp-content/uploads/Finnair_A350_Business_Class_Seat_Champagne_Glass-768x485.jpg 768w, https://fcam.b-cdn.net/blog/wp-content/uploads/Finnair_A350_Business_Class_Seat_Champagne_Glass-1024x646.jpg 1024w, https://fcam.b-cdn.net/blog/wp-content/uploads/Finnair_A350_Business_Class_Seat_Champagne_Glass-237x150.jpg 237w" data-ll-status="loaded" width="1000" height="631">
My question is whether there is anyway to downsize these images if those are exceeding certain width(perhaps 800px) in real. This optimization helps to save lot of bandwidth as per my calculation.
Any help would be really appreciating.
Share Improve this question edited Feb 16, 2022 at 8:03 Janith Chinthana asked Feb 16, 2022 at 6:37 Janith ChinthanaJanith Chinthana 4082 gold badges8 silver badges26 bronze badges1 Answer
Reset to default 1You should look at the following: https://developer.wordpress.org/reference/functions/add_image_size/
eg add this to your theme's functions.php or plugin:
add_image_size( 'newsletter-image', 800, 600 ); // 800 pixels wide by 600 pixels tall, soft proportional crop mode
Then use the image like this:
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'newsletter-image' );
}