How to add Hreflang language tags?
Hreflang tags tell search engines like Google which version of your page to show to which audience. If your site exists in multiple languages or targets different countries, these tags help Google match the right page to the right user.
Why do they matter?
Without them, Google might show a German user your English page, or serve your US content to visitors in the UK. Getting this right improves user experience and search visibility in each market.
How do they work?
You add a small snippet of code to each page that says: "here are all the versions of this page, and which language/region each one is for."
There are three ways to do this — HTML tags, HTTP headers, or a sitemap — and all three work equally well. Pick whichever suits your setup.
The most common method is adding <link> tags in your page's <head>:
html
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="de" href="https://example.com/de/" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
Language and region codes
The hreflang value is made up of a mandatory language code in ISO 639-1 format, followed by an optional region code in ISO 3166-1 Alpha 2 format, separated by a dash — for example, en-US. You cannot specify a country code alone; the language always comes first.
Some examples:
de— German, any regionen-GB— English for users in the UKzh-Hant— Chinese (Traditional)
Use x-default as a fallback for users whose language isn't covered by any of your versions — typically pointing to a language selector page.
The golden rule
Every language version must list itself as well as all other language versions. All alternate URLs must be fully qualified (including https://), and they don't need to be on the same domain. google
The most important rule: if two pages don't both point to each other, the tags will be ignored. This prevents third parties from arbitrarily claiming a page as an alternate version of yours.
Common mistakes
The most frequent errors are missing return links (if page X points to page Y, page Y must point back), incorrect language codes, and invalid region codes. For example, codes like EU, UK, or UN are not valid ISO 3166-1 Alpha 2 region codes and will be ignored by Google.
How to add them?
The setup process depends on your platform. Select yours below and follow the steps to get language tags configured on your site.
- WordPress: you can easily add language tags by installing our plugin.
- Magento: you can easily add language tags by installing our extension.
- Laravel: We've built a Laravel middleware called ClonableLinkHeader that you can drop straight into your application. Register it as global middleware and it will handle the rest. It's been tested on Laravel 8, but should work with other versions too.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Response;
class ClonableLinkHeader {
protected $langData = [
'domain' => 'kb.clobable.net',
'lang_code' => 'nl-nl',
'clones' => [
[
'domain' => 'kb.clobable.net',
'lang_code' => 'en-gb',
],
]
];
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next) {
$response = $next($request);
// Add header after generating response
$response->header('Link', $this->generateHeader($request));
return $response;
}
/**
* Generates Link header for the requested page.
* @param Request $request
* @return string
*/
private function generateHeader(Request $request): string {
$currentUrl = $request->fullUrl();
// Base url
$header = "<$currentUrl>; rel=\"alternate\"; hreflang=\"{$this->langData['lang_code']}\"";
// X-default:
$header .= ", <$currentUrl>; rel=\"alternate\"; hreflang=\"x-default\"";
// Clones
foreach ($this->langData['clones'] as $clone) {
$cloneUrl = str_replace("https://{$this->langData['domain']}", "https://{$clone['domain']}", $currentUrl);
$header .= ", <$cloneUrl>; rel=\"alternate\", hreflang=\"{$clone['lang_code']}\"";
}
return $header;
}
}
- Generic PHP: For other PHP frameworks, you can use the script below. You should place this code into a place which gets executed before every pageload. Your developer can probably help you with finding the correct place. Alternatively, you can also let the PHP application add correct language tags to the HTML.
// Begin clone SEO optimization
$original_domain = "kb.clobable.net";
$requested_page = "https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$clonable_header = "Link: <$requested_page>; rel=\"alternate\"; hreflang=\"nl-nl\", <$requested_page>; rel=\"alternate\"; hreflang=\"x-default\"";
$clonable_header .= ", <". str_replace("https://$original_domain", "https://kb.clobable.net", $requested_page) .">; rel=\"alternate\"; hreflang=\"en-gb\"";
header($clonable_header);
// End clone SEO optimization
- Other: There's no universal solution, so it's worth checking your platform's documentation for guidance on adding language tags. If you're still unsure, our support team is happy to help find the right approach for your setup.
Updated on: 31/03/2026
Thank you!
