- This topic has 14 replies, 3 voices, and was last updated 3 years ago by
David.
-
AuthorPosts
-
March 9, 2023 at 9:23 pm #2562374
keith
Hello,
I confirmed I have the latest version also latest version of proI cannot figure out what the responsive images do not work on desktop and more importantly on mobile? My old theme they worked fine. I purchased generatepress and installed it today. Tried one of the preconfigured ones offered to pro then reverted back to generatepress. Love it other than the image issues great theme. Can you please help?
Sample url in the private notes section.
Thanks in advance!
March 9, 2023 at 9:40 pm #2562390Fernando Customer Support
Hi Keith,
The images seem fine when viewing your site from my end. What’s happening on your end? For clarity, can you share a screenshot?
Uploading Screenshots: https://docs.generatepress.com/article/using-the-premium-support-forum/#uploading-screenshots
March 9, 2023 at 10:05 pm #2562418keith
Thanks for the quick reply!
Attached 3 examples and two urls in the private notes of the malfunction.
March 9, 2023 at 10:26 pm #2562427Fernando Customer Support
I’m not sure I understand. It’s normal that an image’s dimension changes from its intrinsic size depending on the layout. Are you looking to alter them?
March 10, 2023 at 6:00 am #2562857keith
Hello. It should be chosing the closest thumbnail size see all the other image sizes in the code? That’s how the responsive images are designed to work. Instead it’s randomly using the full sized image.
March 10, 2023 at 6:40 am #2562899keith
Hello,
I think I’m being unclear sorry for the confusion
Responsive yes it shows mobile images in a mobile grid
However it’s not choosing the correctly sized images on both desktop on mobile it’s not using the wordpress thumbnail images. It should be chosing the closest thumbnail size see all the other image sizes in the code. Instead it’s randomly using the full sized image or using a suboptimal image. its like the code is overwriting word presses default thumbnailing and image optimization.
March 10, 2023 at 7:05 am #2562919David
StaffCustomer SupportHi there,
just to cover, its WordPress that is responsible for the src-set and sizes properties of the img HTML.
And it is the browsers responsibility for interpreting that data and selecting the appropriate image size.
The only place the theme gets in the way is to do with featured images. We stay out the way of the rest of the time as GP doesn’t have fixed size containers and therefore prescribing sizes would ultimately backfire 9 times out of 10.But to the point… there are 2 main factors here:
1.The sizes attribute in the HTML. We leave this to the WP default eg.
sizes="(max-width: 550px) 100vw, 550pxAnd in most cases it works just fine, by telling the browser to use the the max image size that fills the viewport…. problem is if the image doesn’t fill the viewport ( because the container has padding ) then the browser will make up its own mind.
2. The client device DPR (device pixel ratio).
A DPR of 2.0 is probably the bare minimum for all screensizes now. Most have 3.0 or greater.
Browsers consider this in their image size request.
For example – an image that has a display size of 350px, a browser on a device with a 2.0 DPR would ultimately want to load an image that is 700px. And it will choose the nearest largest size if the exact size is not found.Now this behaviour can be changed, for example WP provides the
wp_calculate_image_sizesfilter hook which means we can write our own sizes attribute for a specific need.One of many examples on the forum can be seen here:
https://generatepress.com/forums/topic/loading-larger-image-on-mobile-and-tablet/#post-2447841And i can do the same for your site if you want… question is whether you want to? considering the DPR point above.
let us know
March 10, 2023 at 8:58 pm #2563658keith
Thank you this makes a lot of sense.
On the image huge images is perhaps another issue wordpress is serving the giant image
like here
url hidden
I don’t understand why it’s serving the largest ammo can on desktop and mobile 1200×1200 it seems to have plenty of thumbnail options?However on the rest. If I wanted to limit the images to 2x retina for phones and such how would I do that? I see the url but I think that code is to limit them to 1x images right?
Thanks in advance for your help.
March 11, 2023 at 7:06 am #2563975David
StaffCustomer SupportThose XX sizes are standard attachment sizes, i assume a plugin has registered those?
I would ignore the idea of
x1andx2retina images. As you would need WP to generate additional attachment sizes to include those, and in reality the majority of devices will now want ax1image. All you end up doing is stuffing more files into your database.But to the function, it can be rewritten to accommodate whatever sizes you want. Let me know
In addition or alternatively you can use the
max_srcset_image_widthfilter to tell WP the largest image to include in the src-set:eg. max size of 768px
function set_max_srcset_width( $max_width ) { $max_width = 768; return $max_width; } add_filter( 'max_srcset_image_width', 'set_max_srcset_width' );March 11, 2023 at 2:24 pm #2564398keith
Hello
There are different images on the blog1 featured image is 800×800 desktop 350×350 mobile
2 others are 550×550 desktop 350×350 mobile
3 similar blog articles are 200×200 desktop unsure the mobile sizeI’d like to limit the mobile
to max 800×800 imageOn desktop I’d like to limit the featured to grab 800×800 and the others to limit them to 550×550, and the similar blog articles to 200×200 (its grabbing the 800×800 and 1100×1100 on desktop sometimes for the 550×550 image currently)
How would I accomplish that?
March 12, 2023 at 3:17 am #2564686David
StaffCustomer SupportFiltering the sizes of specific images isn’t possible without custom development.
What i can offer is:
// set the maximum src-set image size to 800px function set_max_srcset_width( $max_width ) { $max_width = 800; return $max_width; } add_filter( 'max_srcset_image_width', 'set_max_srcset_width' ); // mobile preferred size 350px function db_modify_srcset_sizes($sizes, $size) { $sizes = '(max-width: 768px) 350px, (min-width: 769px) 800px, 100vw'; return $sizes; } add_filter('wp_calculate_image_sizes', 'db_modify_srcset_sizes', 10 , 2);This will:
a) only add images to the src-set that are a max size of 800px
b) prompt the browser to load the 350px image on mobile screen sizesNote – this does not create new image sizes. For example if you uploaded an image that was 550px then that would be the largest available size.
So if you want to manage image sizes in your post content, the best thing to do is to upload an image at the max-size you want to use.
March 12, 2023 at 7:56 pm #2565383keith
Thank you for the help. Love the theme it is fantastic!
The featured ignores this if I set it lower than 800×800 because it’s specified as 800×800 for desktop in the html is there a way to change the code for mobile to be say 350×350?
March 13, 2023 at 3:49 am #2565750David
StaffCustomer SupportThat code should do that ie. a 800px as the largest image , and 350 for small device sizes.
But i don’t see the change in the HTML it should create
Did you add the above snippet ?March 17, 2023 at 10:57 am #2571454keith
Hello yes I tried it but wordpress is ignoring the sizes for different resolutions screenshots in notes. I tried it with or without the vw100 and also at different resolutions no effect.
On the max width attribute that works to limit. I wonder if I have a featured image at 800×800 on desktop (displays 350×350 x retina factor on mobile) and I set that max to 550 will it cause ill effects on the featured image or could that be a solution? Google page speed/lighthouse flags anything above 2x as too large.
March 18, 2023 at 9:39 am #2572380David
StaffCustomer SupportWhich page is google flagging the images ?
-
AuthorPosts
- You must be logged in to reply to this topic.