Home › Forums › WoodMart support forum › Image elements have no explicit width and height
Image elements have no explicit width and height
- This topic has 9 replies, 2 voices, and was last updated 3 years, 9 months ago by
Elise Noromit.
-
AuthorPosts
-
June 19, 2021 at 10:26 pm #300817
benoParticipantHello
how can I fix this bug, set an explicit width and height for image elements to reduce layout drift and improve CLS, it has a huge impact on site load speedAttachments:
You must be logged in to view attached files.June 19, 2021 at 11:21 pm #300831
Elise NoromitMemberHello,
Please provide your site admin access to the private area. Also please provide the steps to reproduce the problem on your site.
Please confirm the permit for us to deactivate the plugins not related to the theme and switch to the parent theme for the while of checking what may take up to 15 minutes. Please make the full backup of your site.
Best Regards
June 19, 2021 at 11:27 pm #300835
benoParticipantSo I deactivated all plugins, but unfortunately with the page speed test I get the same error message, I added the admin access data in the private area
thank you for your helpJune 21, 2021 at 9:19 am #301037
Elise NoromitMemberHello,
Please add this code to the functions.php of the child theme:
function woodmart_category_thumb_double_size( $category ) { $small_thumbnail_size = apply_filters( 'subcategory_archive_thumbnail_size', 'woocommerce_thumbnail' ); $dimensions = wc_get_image_size( $small_thumbnail_size ); $thumbnail_id = get_term_meta( $category->term_id, 'thumbnail_id', true ); $attr_height = 'height="' . esc_attr( $dimensions['width'] ) . '"'; if ( woodmart_loop_prop( 'double_size' ) ) { $small_thumbnail_size = 'woodmart_shop_catalog_x2'; $dimensions['width'] *= 2; if ( $dimensions['height'] ) { $dimensions['height'] *= 2; } else { $dimensions['height'] = $dimensions['width']; } $attr_height = 'height="' . esc_attr( $dimensions['height'] ) . '"'; } if ( $thumbnail_id ) { $image = wp_get_attachment_image_src( $thumbnail_id, $small_thumbnail_size ); $image = $image[0]; } else { $image = wc_placeholder_img_src(); } if ( $image ) { // Prevent esc_url from breaking spaces in urls for image embeds // Ref: https://core.trac.wordpress.org/ticket/23605 $image = str_replace( ' ', '%20', $image ); echo apply_filters( 'woodmart_attachment', '<img src="' . esc_url( $image ) . '" alt="' . esc_attr( $category->name ) . '" width="' . esc_attr( $dimensions['width'] ) . '" ' . $attr_height . ' />', $thumbnail_id, $small_thumbnail_size ); } }
Then clear all the cache, check the issue, if you have any issues, please contact us.
Best Regards
June 22, 2021 at 10:45 pm #301568
benoParticipantHello
i put the code in php in child theme, then i cleared the cache, the issue unfortunately is still therePlease help me
June 23, 2021 at 1:45 pm #301855
Elise NoromitMemberHello,
We see that attributes have appeared. Please clarify.
Best Regards
June 28, 2021 at 12:50 pm #303104
benoParticipantHello,
As described the problem still exists, more and more images appear in the google speed test that they have the same error, please how can I fix it.
So I added the PHP script you sent me to Child theme, it just doesn’t work.
please take a look at the screenshotAttachments:
You must be logged in to view attached files.June 29, 2021 at 4:26 pm #303408
Elise NoromitMemberHello,
Do you have a problem when you switch to the parent theme?
Best Regards
July 6, 2021 at 11:43 am #304795
benoParticipantYes, even when I switch to the parent theme, I get the error message in the google page speed test
July 6, 2021 at 2:34 pm #304852
Elise NoromitMemberHello,
You use the default image widget in the Megamenu and you have set the custom zie, as the result, image attributes are absent. https://take.ms/Uk7CO
WoodMart theme does not influence Elementor default widgets.
In order to solve the issue, we recommend setting one of the predefined sizes: https://take.ms/8PzFFa
Best Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register