Skip Navigation

Resolved

Overview of the issue

You might have a missing ALT tag for the image flag in the Language Switcher.

This is not a bug and is by design.

It is to improve Language Switcher accessibility for screen readers. The ALT tag for the image is not added if the anchor tag already has a title attribute. If an alt attribute is also added then a screen reader for a visually impaired user would indicate that there are two items here and would repeat the language twice. This is done according to the WCAG2.1 AA issues:

If you want to have an ALT tag on the flag image then you can use the following workaround but it is not recommended if you want to follow the Web Content Accessibility Guidelines.

Workaround

Go to the ../wp-content/plugins/sitepress-multilingual-cms/classes/language-switcher/ directory and edit the class-wpml-ls-model-build.php file.

In it, change the following code from:

		            $ret[ $code ]['flag_alt']   = ( $display_name || $display_native ) ? '' : $data['translated_name'];

to:

		            $ret[ $code ]['flag_alt']   = ( $display_name || $display_native ) ? $data['native_name'] : $data['translated_name'];

Alternatively, you can also consider to configure a language switcher with flags only, in that way it will display the ALT.

 

One Response to “Missing ALT tag for flag image in a language switcher”