Hreflang Tag Generator
Create accurate hreflang annotations for your multilingual and multi-regional websites.
Enter Your Base URL
Start by adding the main URL pattern for your website. We'll use this as a template for your language versions.
Enter the URL of the specific page you are generating tags for. Usually the default language or root version (e.g., `/about`, not `/en/about`).
Include Default Version
The x-default hreflang attribute specifies a fallback page when no language/region matches the user's settings.
Typically this is the default language version of the current page, a language selector page, or the main homepage.
URL Structure Best Practices
Subdirectory (example.com/en/)
Often easiest to implement. Best for most sites. All language versions share domain authority.
Subdomain (en.example.com)
Good for distinct site sections. May require separate setup (DNS, hosting). Search engines might treat them slightly more separately.
ccTLD (example.co.uk, example.fr)
Strongest geo-targeting signal. Most resource-intensive. Best for large enterprises.
URL Parameter (?lang=en)
Not recommended by Google for indexing language versions. Use only if other options are impossible.
Add Language & Regional Versions
Add all language and regional versions of the page from Step 1. URLs may auto-populate; verify and edit them.
Language Code (hreflang) | URL | Actions |
---|---|---|
|
||
No language versions added yet. | ||
Quick Fill Options (Overwrites current list)
Hreflang Code Guide
Language Only (e.g., "en")
Targets speakers of a language, regardless of region.
Language + Region (e.g., "en-US")
Targets speakers of a language within a specific region (e.g., English in the US).
x-default
Specifies the default/fallback page when no other version matches the user's language settings.
Formats: Language = ISO 639-1, Region = ISO 3166-1 Alpha-2.
Generated Hreflang Code
Select your implementation method and copy the code. Ensure the full set of tags is present on each language version of the page.
Implementation Notes:
-
Place in the
<head>
section of your HTML. - Every page in every language must include the complete set of hreflang tags.
- Include a self-referential tag for the current page.
Implementation Notes:
- This code is intended for insertion into your XML sitemap file.
Implementation Notes:
- This code should be added to your server's HTTP response headers.
Verification Tip
After implementation, use Google's International Targeting report or third-party hreflang checkers to validate your setup.
Advanced Hreflang Tips
Self-Referential Hreflang:
Always include a hreflang tag for the current page itself. Each page should reference itself along with all other language versions.
Reciprocal Linking:
Ensure that if page A links to page B, page B also links back to page A.
X-Default Tag:
Specify a fallback using the x-default hreflang attribute.
Absolute URLs:
Always use full URLs (https://...).
Consistency:
Keep the same implementation method across your site.
Regular Auditing:
Monitor your site with Google Search Console and other tools for hreflang issues.
Implementation Guide
Follow these platform-specific guides. Replace examples with your actual generated code from Step 3.
WordPress Implementation
Implementation Mode
Choose how you want to implement hreflang tags
Option 1: Using a Plugin (Automatic Site-Wide Implementation)
The easiest method is to use a dedicated plugin that handles hreflang implementation across your entire site automatically.
-
1
Install and activate a plugin like "WPML" (premium), "Polylang" (free/premium), or "Hreflang Tags Lite" (free).
-
2
Configure your language settings in the plugin's dashboard:
- For WPML: Go to WPML → Languages and set up your language options
- For Polylang: Go to Languages → Settings to configure your languages
- For Hreflang Tags Lite: Go to Settings → Hreflang Tags
-
3
Create content in different languages and associate them together. Most plugins provide an interface to connect translated pages.
-
4
The plugin will automatically add appropriate hreflang tags to all pages site-wide.
Automatic plugins handle:
- Automatic tag generation for all pages
- Dynamic URL mapping between language versions
- Self-referential tags on each page
- x-default tag implementation
- XML sitemap integration
Option 2: Using Theme Functions (Automatic Site-Wide Implementation)
For more control, you can add code to your theme that automatically generates hreflang tags for all pages.
-
1
Open your theme's functions.php file or create a custom plugin.
-
2
Add the following code for smart, dynamic hreflang implementation:
function add_dynamic_hreflang_tags() { // Get current URL and URL parts $current_url = home_url( $_SERVER['REQUEST_URI'] ); $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"; $host = $_SERVER['HTTP_HOST']; $uri = $_SERVER['REQUEST_URI']; // Define your languages and their URL patterns $languages = array( 'x-default' => array( 'url_pattern' => $protocol . '://' . $host . preg_replace('/^\/(en|fr|es|de)\//i', '/', $uri), 'is_default' => true ), 'en' => array( 'url_pattern' => $protocol . '://' . $host . '/en' . preg_replace('/^\/(en|fr|es|de)\//i', '/', $uri) ), 'fr' => array( 'url_pattern' => $protocol . '://' . $host . '/fr' . preg_replace('/^\/(en|fr|es|de)\//i', '/', $uri) ), 'es' => array( 'url_pattern' => $protocol . '://' . $host . '/es' . preg_replace('/^\/(en|fr|es|de)\//i', '/', $uri) ), 'de' => array( 'url_pattern' => $protocol . '://' . $host . '/de' . preg_replace('/^\/(en|fr|es|de)\//i', '/', $uri) ) ); // Output hreflang tags foreach ($languages as $lang_code => $lang_data) { echo '<link rel="alternate" hreflang="'.$lang_code.'" href="'.$lang_data['url_pattern'].'" />'."\n"; } } // Hook into wp_head to add hreflang tags to all pages add_action( 'wp_head', 'add_dynamic_hreflang_tags' );
-
3
This will automatically add hreflang tags to all pages on your site, preserving the current page path across languages.
Option 3: Manual Page-by-Page Implementation
For specific pages where you need custom control over hreflang tags:
-
1
Use a plugin like "Yoast SEO" or "Rank Math" that allows page-specific hreflang settings.
-
2
Edit each page and find the "Advanced" or "International SEO" section in the SEO plugin settings.
-
3
Manually specify the hreflang codes and corresponding URLs for each language version.
Recommendation
For most WordPress sites, using a dedicated multilingual plugin like WPML or Polylang provides the most reliable automatic implementation. These plugins also handle other aspects of multilingual sites beyond just hreflang tags.
Shopify Implementation
Implementation Mode
Choose how you want to implement hreflang tags
Option 1: Using Shopify Markets (Automatic Site-Wide Implementation)
If you're using Shopify's built-in markets feature, you can enable automatic hreflang tags across your entire store.
-
1
Go to Settings > Markets in your Shopify admin.
-
2
Click "Add market" to set up different regions and languages.
-
3
Configure the settings for each market:
- Select countries to include in each market
- Choose the language for each market
- Configure currency and pricing settings
- Set up domain or subdirectory URL structure
-
4
Shopify will automatically add hreflang tags to all store pages based on your market settings.
Shopify Markets handles:
- Automatic hreflang tag generation for all pages
- Self-referential and reciprocal hreflang linking
- Country-specific domain or subdirectory structure
- x-default implementation for your primary storefront
- Automatic updates when adding new content
Option 2: Automatic Implementation with Liquid (Site-Wide)
For more control, add dynamic hreflang tags to your theme that will work for all pages.
-
1
Go to Online Store > Themes > Edit code in your Shopify admin.
-
2
Open the theme.liquid file, which is located in the Layout folder.
-
3
Add this dynamic Liquid code before the closing </head> tag:
<!-- Dynamic Hreflang tags --> <link rel="alternate" hreflang="x-default" href="{{ shop.url }}{{ request.path }}" /> <link rel="alternate" hreflang="en" href="{{ shop.url }}{{ request.path }}" /> <link rel="alternate" hreflang="fr" href="{{ shop.url }}/fr{{ request.path }}" /> <link rel="alternate" hreflang="es" href="{{ shop.url }}/es{{ request.path }}" /> <link rel="alternate" hreflang="de" href="{{ shop.url }}/de{{ request.path }}" /> <!-- End hreflang tags -->
-
4
This code automatically includes the current page path in all hreflang URLs, ensuring proper page-to-page mapping across languages.
Option 3: Using a Third-Party App (Automatic Implementation)
Dedicated multilingual apps provide comprehensive automatic hreflang implementation.
-
1
Visit the Shopify App Store and search for "hreflang" or "multilingual".
-
2
Install and configure one of these recommended apps:
- "Langify" - Full multilingual solution with automatic hreflang
- "Weglot" - Translation and hreflang management
- "LangShop" - Advanced multilingual features with hreflang support
-
3
Most apps provide automatic site-wide hreflang tag implementation once you configure your languages, with no manual coding required.
Multilingual apps typically include:
- Automatic translation services
- Language switcher UI elements
- Currency conversion
- Complete hreflang implementation
- SEO optimization for each language
Recommendation
Shopify Markets is the preferred method for most stores as it's natively integrated with Shopify and provides comprehensive international features beyond just hreflang tags. For stores with complex translation needs, a dedicated app may provide more flexibility.
Wix Implementation
Implementation Mode
Wix only supports automatic implementation
Using Wix Multilingual Feature (Automatic Site-Wide Implementation)
Wix's built-in multilingual feature automatically adds hreflang tags to all pages on your site.
-
1
In your Wix dashboard, go to Settings > Languages.
-
2
Click "Add a Language" and select the languages you want to add to your site.
-
3
Configure your language settings:
- Choose between subdirectory (example.com/fr) or subdomain (fr.example.com) structure
- Set your primary language (will be used as x-default)
- Configure the language menu appearance and position
-
4
Translate your content for each added language using Wix's translation interface.
-
5
Wix automatically adds appropriate hreflang tags to all pages, including:
- Self-referential tags on each page
- Tags pointing to all language alternatives
- The primary language as x-default
- Proper URL structure based on your configuration
Wix Multilingual automatically handles:
- Hreflang tag generation for all site pages
- Language switcher UI in your site navigation
- Proper URL structure across languages
- Content translation workflow
- x-default implementation
Verifying Wix's Hreflang Implementation
You can verify that Wix has properly implemented hreflang tags on your site:
-
1
Visit your published Wix site in a browser.
-
2
Right-click and select "View Page Source" or press Ctrl+U (Cmd+Option+U on Mac).
-
3
Search for "hreflang" in the page source. You should see a series of link tags with hreflang attributes.
Limitations of Wix
Wix doesn't provide direct access to the HTML code, so you can't manually adjust the hreflang implementation. While the automatic implementation works well for most sites, if you need a highly customized solution, you may need to consider a different platform.
Drupal Implementation
Implementation Mode
Choose how you want to implement hreflang tags
Option 1: Using the Language Module (Automatic Site-Wide Implementation)
Drupal's core Language module with proper configuration automatically adds hreflang tags to all pages.
-
1
Enable the required modules:
- Language (core module)
- Content Translation (core module)
- Interface Translation (core module)
- Configuration Translation (core module)
drush en language content_translation locale config_translation -y
-
2
Configure languages at Administration > Configuration > Regional and language > Languages:
- Click "Add language" to add all the languages you need
- Set the default language
- Configure the language detection and selection settings
-
3
Configure language detection at Administration > Configuration > Regional and language > Detection and selection:
- Enable and configure URL detection method (recommended for SEO)
- Set language URL patterns (e.g., prefix or domain)
- Adjust detection method weights and order
-
4
Make content translatable at Administration > Configuration > Regional and language > Content language and translation:
- Select which content types should be translatable
- Choose which fields should be translatable
- Configure any custom entities for translation
-
5
Translate your content:
- Go to a content page and click the "Translate" tab
- Add translations for each language
- Link translations together in the translation interface
-
6
Drupal will automatically add the appropriate hreflang tags to all pages across your site.
Drupal's built-in multilingual system handles:
- Automatic hreflang tag generation for all pages
- Self-referential tags on each page
- Proper URL structure based on your configuration
- Reciprocal linking between translated content
- Language switcher block for user navigation
Option 2: Using a Module (Alternative Automatic Implementation)
For more control or specific requirements, you can use dedicated modules.
-
1
Install and enable the Metatag module and its extensions:
composer require drupal/metatag drush en metatag metatag_hreflang -y
-
2
Configure Metatag settings at Administration > Configuration > Search and metadata > Metatag:
- Configure global settings for hreflang tags
- Set up content-type specific configurations
- Define default hreflang values for each language
-
3
Verify hreflang tags are being added to all pages correctly.
Other useful modules for international SEO include:
- Language Switcher Extended - Enhanced language switching
- Entity Translation Optimizer - Improves multilingual performance
- Pathauto - For consistent URL patterns across languages
Option 3: Custom Theme Implementation (Manual Implementation)
For complete control, you can add hreflang tags directly in your theme.
-
1
Create or edit your theme's [THEME_NAME].theme file:
-
2
Add a hook_preprocess_html function to add hreflang tags dynamically:
/** * Implements hook_preprocess_html(). */ function THEME_NAME_preprocess_html(&$variables) { // Get current URL $current_url = \Drupal::request()->getUri(); $path = \Drupal::service('path.current')->getPath(); // Get language list $language_manager = \Drupal::languageManager(); $languages = $language_manager->getLanguages(); $default_language = $language_manager->getDefaultLanguage(); // Get URL generator $url_generator = \Drupal::service('url_generator'); // Add hreflang tags foreach ($languages as $language) { $langcode = $language->getId(); // Generate URL for this language $language_url = $url_generator->generateFromRoute( '
', [], ['language' => $language, 'absolute' => TRUE] ); // Add hreflang link to head $variables['#attached']['html_head'][] = [ [ '#tag' => 'link', '#attributes' => [ 'rel' => 'alternate', 'hreflang' => $langcode, 'href' => $language_url, ], ], 'hreflang_' . $langcode, ]; } // Add x-default (usually points to default language) $variables['#attached']['html_head'][] = [ [ '#tag' => 'link', '#attributes' => [ 'rel' => 'alternate', 'hreflang' => 'x-default', 'href' => $url_generator->generateFromRoute( ' ', [], ['language' => $default_language, 'absolute' => TRUE] ), ], ], 'hreflang_x_default', ]; } -
3
Clear the cache to apply changes:
drush cr
Recommendation
For most Drupal sites, using the built-in Language module provides the most reliable implementation. The core modules work together seamlessly to handle all aspects of multilingual SEO, including hreflang tags. If you have more complex requirements, the Metatag module offers additional flexibility.
Joomla Implementation
Implementation Mode
Choose how you want to implement hreflang tags
Option 1: Using Joomla's Multilingual Associations (Automatic Site-Wide Implementation)
Joomla's built-in multilingual capabilities automatically add hreflang tags to all pages when properly configured.
-
1
Enable and install required languages:
- Go to System > Install Languages
- Select and install all languages you need
- Set the default language in Global Configuration
-
2
Enable the language filter plugin:
- Go to Extensions > Plugins
- Find the "System - Language Filter" plugin and ensure it's enabled
- Configure the plugin settings (recommended settings: detect browser, add alternate meta tags)
-
3
Configure language settings:
- Go to System > Language(s) > Content Languages
- Make sure all needed languages are published
- Configure language codes correctly (these will be used in hreflang tags)
-
4
Create language associations for your content:
- Go to Components > Multilingual Associations
- Select the content type (articles, menu items, etc.)
- Create associations between content in different languages
-
5
Create language-specific home pages and menus:
- Create a menu for each language
- Create home pages for each language
- Associate menus and home pages via Multilingual Associations
-
6
Add a language switcher module:
- Go to Extensions > Modules
- Create a new "Language Switcher" module
- Configure and publish it in a visible position
-
7
Verify hreflang tags are being added automatically:
- Visit your site and view the page source
- Check the <head> section for hreflang link tags
- Ensure all language versions are properly linked
Joomla's Language Filter plugin automatically handles:
- Adding hreflang tags to all associated content
- Self-referential hreflang tags
- Proper URL structure for language versions
- Language detection for visitors
- x-default implementation (configurable)
Option 2: Using SEO Extensions (Automatic Implementation)
For more control, install a dedicated SEO extension that handles hreflang tags.
-
1
Install an SEO extension that supports hreflang:
- SH404SEF - Comprehensive SEO extension with hreflang support
- EFSEO - Lightweight SEO extension with multilingual capabilities
- JoomSEF - SEF URL and SEO features including hreflang
-
2
Configure the extension settings:
- Enable hreflang tag generation in the extension settings
- Configure language associations if required by the extension
- Set default language and x-default behavior
-
3
Verify the tags are being added correctly to all pages.
Option 3: Template Override (Manual Implementation)
For complete control, you can add hreflang tags directly to your template.
-
1
Create a template override for the head section:
- Navigate to /templates/[YOUR_TEMPLATE]/html/layouts/joomla/system
- If the directory doesn't exist, create it
- Copy the file from /layouts/joomla/system/html.php to this directory
-
2
Edit the html.php file to add custom PHP code that generates hreflang tags:
<?php /** * Template override for generating hreflang tags */ defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Router\Route; // Add original file content here... // Get the application $app = Factory::getApplication(); $doc = Factory::getDocument(); // Only proceed if site is multilingual if (Multilanguage::isEnabled()) { // Get the current URI $uri = JUri::getInstance(); $current = $uri->toString(['scheme', 'host', 'port', 'path', 'query']); // Get current menu item $menu = $app->getMenu(); $active = $menu->getActive(); if ($active) { // Get the Language associations $assoc = JLanguageAssociations::getAssociations('com_menus', '#__menu', 'com_menus.item', $active->id); // Get all site languages $languages = JLanguageHelper::getLanguages(); // Add hreflang tags for each language foreach ($languages as $language) { $langCode = $language->lang_code; // Skip languages without associations if (!isset($assoc[$langCode])) { continue; } // Create the URL for this language $itemid = $assoc[$langCode]->id; $router = $app->getRouter(); // Build the language URL $uri = clone JUri::getInstance(); $uri->setVar('Itemid', $itemid); $uri->setVar('lang', $langCode); // Add the tag $doc->addHeadLink($uri->toString(['scheme', 'host', 'port', 'path', 'query']), 'alternate', 'rel', ['hreflang' => $langCode]); } // Add x-default (using default language) $defaultLang = JComponentHelper::getParams('com_languages')->get('site'); if (isset($assoc[$defaultLang])) { $itemid = $assoc[$defaultLang]->id; $uri = clone JUri::getInstance(); $uri->setVar('Itemid', $itemid); $uri->setVar('lang', $defaultLang); $doc->addHeadLink($uri->toString(['scheme', 'host', 'port', 'path', 'query']), 'alternate', 'rel', ['hreflang' => 'x-default']); } } } // Continue with the rest of the original file... ?>
-
3
Clear the Joomla cache and check if the hreflang tags are appearing correctly.
Recommendation
For most Joomla sites, using the built-in multilingual capabilities with the Language Filter plugin provides the simplest and most reliable implementation. Make sure to properly associate all content between languages to ensure complete hreflang coverage.
Laravel Implementation
Implementation Mode
Choose your implementation method
Option 1: Middleware (HTTP Headers)
Create middleware to add hreflang headers to non-HTML responses or if you prefer header-based implementation.
- Create middleware with
php artisan make:middleware HreflangHeaders
. - Add the following code to the middleware:
namespace App\Http\Middleware; use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; class HreflangHeaders { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle(Request $request, Closure $next) { $response = $next($request); // Get current locale $currentLocale = App::getLocale(); // Define supported locales with their corresponding domains/paths $locales = [ 'en' => 'https://example.com', 'fr' => 'https://example.com/fr', 'es' => 'https://example.com/es', 'de' => 'https://example.com/de', ]; // Get current path $path = $request->path(); if ($path !== '/') { $path = '/' . $path; } // Generate link header parts $links = []; // Add x-default (typically points to default locale version) $links[] = '<' . $locales['en'] . $path . '>; rel="alternate"; hreflang="x-default"'; // Add all locales foreach ($locales as $locale => $domain) { $links[] = '<' . $domain . $path . '>; rel="alternate"; hreflang="' . $locale . '"'; } // Set header if we have links if (!empty($links)) { $response->header('Link', implode(', ', $links)); } return $response; } }
Then register the middleware in app/Http/Kernel.php
:
protected $middleware = [ // ... other middleware \App\Http\Middleware\HreflangHeaders::class, ];
What this code does:
- Creates Laravel middleware that runs on every request
- Gets the current locale and path information
- Creates an x-default hreflang reference
- Generates Link headers for all supported languages
- Attaches the Link headers to the HTTP response
Option 2: View Composer / Helper (HTML Tags)
Create a view composer or helper function to generate hreflang tags and insert them into your HTML head.
- Create a new View Composer by running
php artisan make:provider HreflangServiceProvider
- Add the following code to the provider:
namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Request; class HreflangServiceProvider extends ServiceProvider { /** * Register services. * * @return void */ public function register() { // } /** * Bootstrap services. * * @return void */ public function boot() { // Share hreflang data with all views View::composer('*', function ($view) { $currentLocale = App::getLocale(); // Define supported locales with their corresponding domains/paths $locales = [ 'en' => 'https://example.com', 'fr' => 'https://example.com/fr', 'es' => 'https://example.com/es', 'de' => 'https://example.com/de', ]; // Get current path $path = Request::path(); if ($path !== '/') { $path = '/' . $path; } // Generate hreflang tags HTML $hreflangTags = ''; // Add x-default $hreflangTags .= '' . "\n"; // Add all locales foreach ($locales as $locale => $domain) { $hreflangTags .= '' . "\n"; } $view->with('hreflangTags', $hreflangTags); }); } }
Register the service provider in config/app.php
:
'providers' => [ // ... other providers App\Providers\HreflangServiceProvider::class, ],
Then in your main layout file (usually resources/views/layouts/app.blade.php
), add:
<head> <!-- ... other head elements ... --> {!! $hreflangTags !!} <!-- ... other head elements ... --> </head>
What this code does:
- Creates a View Composer that shares hreflang data with all views
- Defines supported locales and their corresponding URLs
- Generates HTML link tags for all languages
- Includes an x-default tag for fallback
- Makes the tags available to be inserted in your layout's <head> section
Recommendation: Option 2 (View Composer/Helper) is often the simplest solution for HTML-based hreflang tags.
Custom CMS Implementation
Consult your CMS documentation for adding code to your page templates. Look for options such as template editing, hooks, or custom fields that let you insert code into the <head>
section. This method does not include a manual/automatic toggle.
Need Expert Help?
Our international SEO specialists can help you implement and verify hreflang tags correctly.
Advanced Hreflang Tips
Self-Referential Hreflang
Always include a hreflang tag for the current page itself. Each page should reference itself along with all other language versions.
X-Default Tag
Use the x-default tag to specify a fallback page for users whose language preferences don't match any of your language versions.
Reciprocal Linking
Ensure that if page A links to page B, page B also links back to page A.
Identical URL Structure
Maintain identical URL structures across language versions to simplify implementation and maintenance.
Regular Auditing
Use Google Search Console's International Targeting report to identify and fix hreflang implementation errors.
Need Expert Help?
Our international SEO specialists can help you implement and verify hreflang tags correctly.
Thank You!
We'll be in touch shortly!