Home›Support›English Support›[Resolved] Language Switcher Block has no width/height attributes for language flags
[Resolved] Language Switcher Block has no width/height attributes for language flags
This thread is resolved. Here is a description of the problem and solution.
Problem: I'm facing an issue where Google PageSpeed Insights is flagging images without width/height attributes. This problem arises with both built-in svg flags and custom png flags in the language switcher plugin, as shown in my attached screenshot.
Solution: Modify the code in `wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/Blocks/LanguageSwitcher/Render.php`. Specifically, in the method `\WPML\BlockEditor\Blocks\LanguageSwitcher\Render::createLanguageItemNode`, update the code to set the 'src', 'width', and 'height' attributes for the flags, ensuring that the 'width' and 'height' values are numerical without any units like 'px'. The updated code snippet provided should resolve the issue with Google PageSpeed Insights flagging the images.
Google PageSpeed Insights doesn't like images without width/height attribute. They are not correctly set through language switcher plugin, see screenshot attached. This occurs with built in svg flags and custom png flags.
Languages: English (English )German (Deutsch )French (Français )
Timezone: Europe/Zagreb (GMT+02:00)
Can you try this:
Go to: wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/Blocks/LanguageSwitcher/Render.php
Change in the method: \WPML\BlockEditor\Blocks\LanguageSwitcher\Render::createLanguageItemNode
Languages: English (English )German (Deutsch )French (Français )
Timezone: Europe/Zagreb (GMT+02:00)
User confirmed that this is resolved
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.