This thread is resolved. Here is a description of the problem and solution.
Problem:
Language switcher flag image missing alt attribute.
Solution:
Got to ../wp-content/plugins/sitepress-multilingual-cms/classes/language-switcher/ directory and edit the class-wpml-ls-model-build.php, line 190.
Remove this line:
$ret[ $code ]['flag_alt'] = ( $display_name || $display_native ) ? '' : $data['translated_name'];
And replace it with this line:
$ret[ $code ]['flag_alt'] = ( $display_name || $display_native ) ? $data['native_name'] : $data['translated_name'];
Relevant Documentation:
https://wpml.org/errata/missing-alt-tag-for-flag-image-in-a-language-switcher/
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.
Tagged: Documentation request
This topic contains 4 replies, has 2 voices.
Last updated by tomasJ-15 1 year, 7 months ago.
Assisted by: Eran Helzer.
Author | Posts |
---|---|
May 27, 2023 at 1:55 pm #13726293 | |
tomasJ-15 |
Hello, <img class="wpml-ls-flag" src="hidden link" alt="" width="18" height="12"> |
May 29, 2023 at 8:41 am #13729793 | |
Eran Helzer Supporter
Languages: English (English ) Hebrew (עברית ) Timezone: Asia/Jerusalem (GMT+02:00) |
Hi, The documentation you followed is indeed what you need to do to achieve what you want. I followed it just now and it worked for me. Can you please let me know if: You followed the exact steps from the errata and it still didn't work, or if you had any trouble following it? Regards, |
May 29, 2023 at 12:55 pm #13732499 | |
tomasJ-15 |
Dear Eran, there is no line: $ret[ $code ]['flag_alt'] = ( $display_name || $display_native ) ? '' : $data['translated_name']; ________________________________ class WPML_LS_Model_Build extends WPML_SP_User { const LINK_CSS_CLASS = 'wpml-ls-link'; /* @var WPML_LS_Settings $settings */ /* @var WPML_Mobile_Detect $mobile_detect */ /* @var bool $is_touch_screen */ /* @var string $css_prefix */ private $allowed_vars = [ private $allowed_language_vars = [ /** /** $vars['current_language_code'] = $this->sitepress->get_current_language(); $vars = $this->add_backward_compatibility_to_wrapper( $vars, $slot ); return $this->sanitize_vars( $vars, $this->allowed_vars ); /** $classes[] = trim( $this->css_prefix, '-' ); if ( $this->sitepress->is_rtl( $this->sitepress->get_current_language() ) ) { $classes = $this->add_user_agent_touch_device_classes( $classes ); /** return implode( ' ', $classes ); /** /** /** $get_ls_args = [ if ( $slot->is_post_translations() ) { $flag_width = $slot->get( 'include_flag_width' ); $languages = $this->sitepress->get_ls_languages( $get_ls_args ); if ( $languages ) { foreach ( $languages as $code => $data ) { $is_current_language = $code === $this->sitepress->get_current_language(); if ( ! $slot->get( 'display_link_for_current_lang' ) && $is_current_language ) { $ret[ $code ] = [ if ( $flag_width ) { /* @deprecated Use 'wpml_ls_language_url' instead */ /** $ret[ $code ]['url'] = $this->sitepress->get_wp_api()->is_admin() ? '#' : $ret[ $code ]['url']; $css_classes = $this->get_language_css_classes( $slot, $code ); $display_native = $slot->get( 'display_names_in_native_lang' ); if ( $slot->get( 'display_flags' ) ) { if ( $display_native ) { if ( $display_name ) { if ( $is_current_language ) { if ( $slot->is_menu() ) { array_unshift( $css_classes, 'menu-item' ); $ret[ $code ]['css_classes'] = $css_classes; $i = 1; if ( $i === count( $ret ) ) { $lang = $this->add_backward_compatibility_to_languages( $lang, $slot ); /** $lang['css_classes'] = implode( ' ', $lang['css_classes'] ); $lang = $this->sanitize_vars( $lang, $this->allowed_language_vars ); } return $ret; /** if ( ! $has_custom_flag && ! empty( $template_data['flags_base_uri'] ) ) { if ( isset( $template_data['flag_extension'] ) ) { return $url; /** /** if ( is_null( $this->mobile_detect ) ) { if ( $this->is_touch_screen ) { return $classes; /** /** /** foreach ( $allowed_vars as $allowed_var => $type ) { case 'string': case 'int': case 'bool': case 'mixed': return $sanitized; /** if ( $this->needs_backward_compatibility() ) { $is_current_language = isset( $lang['is_current'] ) && $lang['is_current']; if ( $slot->is_menu() ) { if ( $is_current_language ) { array_unshift( $lang['css_classes'], 'menu-item-language' ); if ( $slot->is_sidebar() || $slot->is_shortcode_actions() ) { if ( $this->is_legacy_template( $slot->template(), 'list-vertical' ) if ( $this->is_legacy_template( $slot->template(), 'dropdown' ) if ( $is_current_language ) { return $lang; /** if ( $this->needs_backward_compatibility() ) { if ( $slot->is_sidebar() || $slot->is_shortcode_actions() ) { if ( $this->is_legacy_template( $slot->template(), 'list-vertical' ) if ( $this->is_legacy_template( $slot->template(), 'list-horizontal' ) ) { if ( $this->is_legacy_template( $slot->template(), 'dropdown' ) ) { if ( $this->is_legacy_template( $slot->template(), 'dropdown-click' ) ) { if ( $slot->is_post_translations() ) { if ( $slot->is_footer() ) { $vars['backward_compatibility']['css_classes_flag'] = 'iclflag'; return $vars; /** if ( $ret && array_key_exists( $type, $templates ) ) { return $ret; |
May 30, 2023 at 5:40 am #13735887 | |
Eran Helzer Supporter
Languages: English (English ) Hebrew (עברית ) Timezone: Asia/Jerusalem (GMT+02:00) |
Hi, It is good that you gave the entire file, I now see the issue. The line in question is line number 190. If you delete it entirely and replace it with the following line then the images will have ALT attributes: $ret[ $code ]['flag_alt'] = ( $display_name || $display_native ) ? $data['native_name'] : $data['translated_name']; If you need any further assistance, don't hesitate to ask. Regards, |