Archived topic
"Image elements do not have explicit width and height" error using GP 2.03
7 replies · Started by Clayton on July 7, 2021
I'm getting this error in the Google Page Speed test "Image elements do not have explicit width and height". There are two issues.
- Even thought I've been told that GP 2.0 patched this issue I still get this error unless I add the function provided by Tom
- On the website I've included in the Private Information I still get this error even with the function added
Hi there,
thanks for raising the new topic - in the previous topic this fix was referenced:
https://generatepress.com/forums/topic/logo-does-not-have-explicit-width-and-height/#post-1762272
Which should resolve the problem.
How did you add the function to your site?
And can you also ensure that any lazy loaders are temporarily disabled and all caches cleared after adding it.
If its still a problem then remove the logo and reupload it with a new filename ( with lazyloaders disabled ) and then recheck the site for missing attributes.
I added the function via the Code Snippets plugin. I will deactivate image lazy loading and clear cache and try again.
Let us know.
Hey David,
So I've excluded the logo from lazy load and turned lazy loading all together and completely cleared all cookies and caches but still seeing that error. I even tried activating the Image Dimensions feature in WP Rocket which is supposed to fix that issue but still no luck.
I can see width and height attributes now... but they both have a value of 1 - so if that function is still in place its kinda working but just cannot the sizes from the image.
So remove that snippet and try this instead:
add_filter('generate_logo_attributes', function($output){
$add_attr = array(
'width' => '284',
'height' => '89',
);
$new_output = array_merge($output,$add_attr);
return $new_output;
});
This is so weird. I see that the logo has height and width set now but I'm still getting the error on the Google Page Speed test. At this point I think I'm not going to worry about it because it seems like an issue with Google's Test not GP. Thank you for taking the time to help and update the function. I appreciate it.
No problems :)