Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client needed a way to customize the ALT text for flag images in the WPML language switcher to improve accessibility and comply with WCAG 1.1.1, without modifying WPML core files.
Solution:
We advised the client that currently, the best approach to achieve the desired ALT text customization is to follow the workaround provided in our errata, which involves modifying the 'class-wpml-ls-model-build.php' file.

https://wpml.org/errata/missing-alt-tag-for-flag-image-in-a-language-switcher/

Unfortunately, there are no suitable hooks or filters available for this customization, and implementing custom code would be complex. We also informed the client that there is no ETA for a permanent fix but have taken their feedback as a feature request. We recommended trying the workaround after ensuring a site backup.

Please note that this solution might be outdated or not applicable to your specific case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If this does not resolve your issue, please open a new support ticket at WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by Bigul 1 month ago.

Assisted by: Bigul.

Author Posts
October 17, 2024 at 3:34 pm #16301220

laurensB-4

Background of the issue:
I've encountered an accessibility issue with the ALT text for flag images in the WPML language switcher. To improve accessibility and comply with WCAG 1.1.1, I need to provide more descriptive ALT text for these images, something like 'Switch to Dutch language'. I found a workaround that involves modifying the file 'class-wpml-ls-model-build.php' in the WPML core directory (https://wpml.org/errata/missing-alt-tag-for-flag-image-in-a-language-switcher/). While this workaround works, I'm concerned about modifying core files, as these changes could be lost during plugin updates.

Symptoms:
Accessibility issue with the ALT text for flag images in the WPML language switcher.

Questions:
Is there a proper way to customize the ALT text for language switcher flags without modifying WPML core files?
Does WPML provide any filters or hooks that would allow me to achieve this customization safely?
If not, are there plans to implement such functionality in future WPML versions?

October 18, 2024 at 6:17 am #16302738

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Welcome to the WPML support forum. I will do my best to help you to resolve the issue.

To help you faster, I've enabled debug information for this support ticket. Please see this link for how to get this information from your site and give it to us: http://wpml.org/faq/provide-debug-information-faster-support/

I will consult about our team for an expert opinion on this and get back to you soon. Please wait.

--
Thanks!

Bigul

October 18, 2024 at 3:00 pm #16305343

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

For your kind information, our developers have confirmed that the best approach to achieve the desired functionality would be to modify the code directly, as described in the workaround provided in the errata. Unfortunately, there is no suitable hook available for this, and custom code approaches would be quite complex.

https://wpml.org/errata/missing-alt-tag-for-flag-image-in-a-language-switcher/

At this time, we do not have an ETA for the release of a permanent fix. Therefore, we kindly request that you proceed with the workaround suggested in the errata.

Thank you for your understanding. Please let us know if you need further assistance.

--
Thanks!

Bigul

October 21, 2024 at 2:25 pm #16312903

laurensB-4

Hi Bigul,

Modifying core files isn’t a viable solution because those changes will be overwritten with every update, which would mean having to reapply the customization each time.

Why don't you implement a filter? This should be a small and easy change.

October 22, 2024 at 1:29 pm #16317664

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Thank you for your feedback. I have shared it with our team and will be considered as a feature request.

I can see a similar ticket. Maybe you can try the workaround suggested there. Please try it after a site backup.

https://wpml.org/forums/topic/empty-alt-tag/#post-4894673

--
Thanks!

Bigul