- This topic has 9 replies, 2 voices, and was last updated 4 years, 11 months ago by
Elvin.
-
AuthorPosts
-
April 19, 2021 at 3:27 am #1739893
Charbel
Hello @David,
Hope all is well.
Could you please help in solving the Home page images issue for WP Show Posts?
Image elements do not have explicit width and height
Google PageSpeed Insights is complaining about all the 11 images. I am already using WP Show Posts Version 1.2.0-alpha.3.
I am also using WP Rocket with Image Dimensions (Add missing image dimensions) enabled, but the issue still persists.
Your help is highly appreciated.
Homepage: https://charbelnemnom.com
Thank You!
-CharbelApril 19, 2021 at 5:10 pm #1740937Elvin
StaffCustomer SupportHi there,
Can you share with us your image settings for the list wpsp-18404?
Did you have an image width and height value assigned to it prior to updating to 1.2.0-alpha.3? Let us know.
April 19, 2021 at 9:33 pm #1741094Charbel
Hello @Elvin,
Thank you for your kind support.
Yes, I remember that I have an image width and height prior to updating to 1.2.0-alpha.3 but it’s the same to below settings. In fact, Codeable did the migration of my site so I can’t confirm 100%.
Here are the image settings for the list wpsp-18404.
Image width (px) = 400
Image heights (px) = 225
Image alignment = Center
Image location = Above titleCould you please advise?
Thank You, Elvin!
-CharbelApril 20, 2021 at 3:27 pm #1742352Elvin
StaffCustomer SupportYes, I remember that I have an image width and height prior to updating to 1.2.0-alpha.3 but it’s the same to below settings. In fact, Codeable did the migration of my site so I can’t confirm 100%.
Ah i see. Can you remove the image width and height values? That’s actually the one causing the issue. The older version of WPSP removes the attribute and directly applies the cropping/resizing on the image. You can actually see the img src if you inspect the page. The image paths have 400×225 suffix on them.
WPSP 1.2.0-alpha.3 changed how the image sizing is done because the old one causes this exact issue.
See changelog here- https://wpshowposts.com/wp-show-posts-1-2-0/The preferred way on changing image size on the newest WPSP is by adding an image size and use it’s name on the “Image size” text field.
Example way of adding an image:
add_action( 'init', function() { add_image_size( 'wpsp-image', 400, 225, true ); } );You then use
wpsp-imageon the Image size field.Note: “Image size” field replaced image height and image width field on 1.2.0, but is still kept if your WPSP list had one on the previous version. Removing the Image Height and Image Width values and updating the list should replace the old field with the new Image size field.
April 20, 2021 at 9:39 pm #1742547Charbel
Thank you @Elvin, much appreciated!
I have removed the image width and height values from wpsp-18404, and the issue (Image elements do not have explicit width and height) is resolved on Google PageSpeed Insights.
However, now I am getting another recommendation about properly size images. Those are the same images displayed in WPSP.
I followed your guidance, by adding this code to my child theme functions.php
add_action( 'init', function() { add_image_size( 'wpsp-image', 400, 225, true ); } );And then I updated my wpsp-18404 by adding wpsp-image on the Image size field.
I cleared the cache and still GPSI suggesting to properly size my images.
Could you please help?
Many Thanks!
April 20, 2021 at 11:46 pm #1742669Elvin
StaffCustomer SupportYou need to regenerate the image after adding the image size. WordPress doesn’t automatically generate it for images uploaded prior to adding that image size. 🙂
You can do it with this plugin.
https://wordpress.org/plugins/regenerate-thumbnails/April 21, 2021 at 6:30 am #1743045Charbel
Thank you @Elvin for the tip!
Finally, this issue is resolved now. GPSI is happy 🙂
I have regenerated all my Thumbnails by using reGenerate Thumbnails Advanced by Short Pixel. I use their image optimizer plugin as well.
https://wordpress.org/plugins/regenerate-thumbnails-advanced/
Now, if I understood well. Every new image that I upload, it will be set by GeneratePress Theme based on the function that we set 400×225, right? so nothing to change afterward.
Thank You!
April 21, 2021 at 3:42 pm #1743807Elvin
StaffCustomer SupportNow, if I understood well. Every new image that I upload, it will be set by GeneratePress Theme based on the function that we set 400×225, right? so nothing to change afterward.
Not by the theme but by the PHP snippet you’ve used. It’s a WordPress core function. It’s theme independent. It will work regardless of what theme you’re using.
And yeah, after applying the snippet, all the images uploaded should generate a size for the one you’ve added.
April 21, 2021 at 10:38 pm #1744033Charbel
Thank You @Elvin, much appreciated!
April 21, 2021 at 10:46 pm #1744042Elvin
StaffCustomer SupportNo problem. Glad to be of any help. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.