Add title attribute to hreflang meta links
-
The generated hreflang meta links don’t contain a descriptive title, just the language.
This will cause screen readers or text based browser to just output “alternate link” as description (you can verify this using Lynx). Also see the screenshots in my post about improved accessibility: http://arnowelzel.de/wp/en/improve-accessibility-with-skip-to-content-links
Better: Output the descriptions as title attribute using the following version of
msls_head()
inMultisiteLanguageSwitcher.php
(based on version 1.0.4):function msls_head() { $blogs = MslsBlogCollection::instance(); $mydata = MslsOptions::create(); foreach ( $blogs->get_objects() as $blog ) { $language = $blog->get_language(); $url = $mydata->get_current_link(); $current = ( $blog->userblog_id == MslsBlogCollection::instance()->get_current_blog_id() ); $title = $blog->get_description(); if ( ! $current ) { switch_to_blog( $blog->userblog_id ); if ( 'MslsOptions' != get_class( $mydata ) && ( is_null( $mydata ) || ! $mydata->has_value( $language ) ) ) { restore_current_blog(); continue; } $url = $mydata->get_permalink( $language ); $title = $blog->get_description(); restore_current_blog(); } if ( has_filter( 'msls_head_hreflang' ) ) { /** * Overrides the hreflang value * @since 0.9.9 * @param string $language */ $hreflang = (string) apply_filters( 'msls_head_hreflang', $language ); } else { $hreflang = $blog->get_alpha2(); } printf( '<link rel="alternate" hreflang="%s" href="%s" title="%s" />', $hreflang, $url, esc_attr($title) ); echo "\n"; } }
This way also screen readers or other browsers which display meta links as selectable elements will display a descriptive text and not just multiple “alternate link” entries.
Also see my site http://arnowelzel.de as an example – there I includede the proposed modifications as above.
https://wordpress.org/plugins/multisite-language-switcher/
Edit: Added
esc_attr()
for the title to be safe.
- The topic ‘Add title attribute to hreflang meta links’ is closed to new replies.