Replacing underscores by hyphens in hreflang
-
I am currently running a WP multisite with two different versions that I want to show different “language-country” hreflangs for in my header. I managed to add the following code to my functions.php file in order to make the country code appear in the hreflang as well:
Code added to functions.php
/** * @param string $language * @return string */ function my_msls_head_hreflang( $language ) { if ( 'en' == $language ) { $language = 'en-us'; } return $language; } add_filter( 'msls_head_hreflang', 'my_msls_head_hreflang' );
Now the hreflang tags shown in my header use underscores (_) instead of hyphens (-). However, they need to be hyphens as this is the only format search engines will recognize.
Now my hreflangs look like this:
<link rel="alternate" hreflang="en_US" href="https://example.com/" /> <link rel="alternate" hreflang="en_GB" href="https://example.com/gb/" />
While they should look like this:
<link rel="alternate" hreflang="en-US" href="https://example.com/" /> <link rel="alternate" hreflang="en-GB" href="https://example.com/gb/" />
I have my WPLANG in my multisite settings configured with underscores: “en_US” for instance. Changing this however doesn’t seem to make a difference.
Any thoughts?
https://www.ads-software.com/plugins/multisite-language-switcher/
- The topic ‘Replacing underscores by hyphens in hreflang’ is closed to new replies.