New!

Introducing TranslatePress AI The fastest way to translate your WordPress Website

Learn More
0
Days
0
Hours
0
Minutes
0
Seconds

Last Chance Sale 25% OFF! Our only sale of the year ends soon!

Use Discount code BF2024 at Checkout. Bottom link

Documentation > Developers > Change hreflang localization

Change hreflang localization

Browse Docs
Search Documentation

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.