Change hreflang localization

TranslatePress sets meta tags inside the HTML page to help Google and other indexing engines understand the languages and locations in which a specific page is available.

The hreflang attribute is a part of this meta tag where the language and location are specified.

You can change it using a bit of coding.

How to change hreflang meta

1. Create an empty plugin like this:
https://gist.github.com/sareiodata/76f701e01db6685829db

2. Add the following code to the end of it:

add_filter('trp_hreflang', 'trpc_change_hreflang', 10, 2 );
function trpc_change_hreflang( $hreflang, $language ){
if ($language == 'fr_FR'){ // language code that you want to alter

// the modified hreflang code you want to display in the page
$hreflang = 'fr-CH';
}
return $hreflang;
}

3. Modify the code by editing the language code and the hreflang code. The rest of the hreflang codes will not change.

4. Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality.

Looking to go multilingual?

Get full access to TranslatePress and join 300.000+ website owners that grow their multilingual traffic.

Unlock PREMIUM Features

Or download FREE version