Fixing og:locale Issues
The og:locale tag tells sharing platforms which language, and which regional variety of it, a page is written in.
It is one of the smaller Open Graph properties, but it is also one of the most often wrong: British sites announce themselves as American English because a setting was never changed, codes are written with a hyphen or with UK instead of GB, and multilingual sites list every language on every page. This guide explains the exact format, where a wrong value comes from, how to generate the right one, and when og:locale:alternate belongs in the block.
The format og:locale expects
The Open Graph protocol defines og:locale as the locale the tags are marked up in, written
as language_TERRITORY. If the tag is absent, the protocol says readers should assume en_US.
That default is the reason the tag matters to a British site at all: without it, you are formally declaring
American English.
- Language is a two-letter lower-case code from ISO 639-1:
en,cy,fr,de,pl. - Territory is a two-letter upper-case country code from ISO 3166-1:
GB,IE,US,FR. - The separator is an underscore, not a hyphen.
| Value found | Problem | Correct value |
|---|---|---|
en-GB | Hyphen instead of underscore; this is the lang attribute
format | en_GB |
en_UK | UK is not the ISO country code for the United Kingdom | en_GB |
EN_gb | Case reversed | en_GB |
en | No territory | en_GB, or whichever country the content is written for |
en_US on a British site | Valid, but describes the wrong variety of English | en_GB |
english or British English | A name, not a code | en_GB |
cy_WA for Welsh | WA is not a country code; Wales falls under
GB | cy_GB |
The United Kingdom's ISO code is GB. UK is reserved in the standard but
is not the code assigned to the country, so a strict reader treats en_UK as unknown. The
same code is used for every nation within the UK: English in Scotland is en_GB, Welsh is
cy_GB, Scottish Gaelic is gd_GB. For the Republic of Ireland, English is en_IE
and Irish is ga_IE.
How much it matters, honestly
A wrong og:locale will not usually break a link card. The title, description and image
appear whatever the locale says. So it is fair to ask why a validator flags it.
- It is metadata other systems may read. Platforms, aggregators, feed readers and
language tools can use the declared locale to classify content. A British recipe site declaring
en_USis giving them wrong information, even if nobody sees it directly. - It is a symptom. An
en_USvalue on a UK site usually means the CMS language setting was never changed. The same setting often controls date formats, spelling in theme strings and thelangattribute, which screen readers use to pick a pronunciation. Fixing the locale often fixes those too. - It matters more on multilingual sites. When a French page declares
en_GBbecause the locale is hard-coded in a shared layout, every French card is labelled as English.
What og:locale does not do is tell Google which country to show a page in. Google uses
hreflang annotations and other signals for that. Treat og:locale as accurate
labelling for sharing platforms, not as a search targeting tool.
Where a wrong value comes from
Very few people type an og:locale value by hand. It is usually derived from a language
setting somewhere else, and the error is in that setting or in the conversion.
A CMS language left on the default
WordPress installs in American English unless you choose otherwise, and SEO plugins such as Yoast
and Rank Math build og:locale from the site language. If Settings โ General โ Site
Language says English (United States), the tag says en_US. Switching it to English
(UK) changes the tag to en_GB, and also changes the language of the admin screens and some
theme text.
A hyphenated code passed straight through
Many systems store locales as en-GB, the BCP 47 form used by the lang attribute
and hreflang. A template that prints that value straight into og:locale gives
the hyphen form. The fix is a conversion, covered below, not a different setting.
A language with no country
Shopify, many headless CMSs and some translation plugins store just the language, en
or fr, for each version of a site. Printing that alone gives a code with no territory. Combine
it with the market's country code, or map it to a full code.
A hard-coded value in a shared layout
On multilingual sites, og:locale is sometimes written once in the base layout. Every
language then declares the same locale. The value has to come from the language of the page being rendered.
Generating the right value in code
Keep one source of truth for a page's language, usually the BCP 47 form such as en-GB,
because that is what lang and hreflang need. Derive the Open Graph form from
it with a small conversion that also rejects the UK mistake.
function toOgLocale(tag, fallbackCountry = 'GB') {
const [lang, region] = String(tag).replace('_', '-').split('-');
let country = (region || fallbackCountry).toUpperCase();
if (country === 'UK') country = 'GB';
return `${lang.toLowerCase()}_${country}`;
}
toOgLocale('en-GB'); // en_GB
toOgLocale('en_uk'); // en_GB
toOgLocale('cy'); // cy_GB
toOgLocale('fr', 'FR'); // fr_FR
The same idea works in any template language. In PHP, str_replace('-', '_', $tag) followed
by fixing the case does most of the work. The important part is that the fallback country is a decision
you make for your site, not the protocol's US default.
Next.js
The Metadata API has dedicated fields. Set openGraph.locale in the root layout and override
it in any route that serves another language.
export const metadata = {
openGraph: {
locale: 'en_GB',
siteName: 'Harlow Street Bakery',
},
};
Shopify
If your theme prints og:locale, build it from the storefront's language and market country
rather than typing a value. The Liquid objects request.locale.iso_code and localization.country.iso_code
give you the two parts; take only the language part of the first, join them with an underscore, and print
the result.
{%- assign og_lang = request.locale.iso_code | split: '-' | first -%}
<meta property="og:locale" content="{{ og_lang }}_{{ localization.country.iso_code }}">
Check the output on each market you run, because a store selling to several countries in one language will then declare a different territory for each market, which is accurate.
The fix, step by step
Step 1
Read the current locale values
Run
a page through the OG / Twitter Tag Generator and note what it reports for the locale, then open view-source
and search for og:locale. Record the primary value, every og:locale:alternate
value, and the lang attribute on the html element. On a multilingual site,
repeat this for one page in each language, because a hard-coded value only shows up when you compare
languages side by side.
Step 2
Work out the correct code
Decide
the language the page is actually written in and the country whose conventions it follows. A UK business
writing British English needs en_GB; Welsh pages need cy_GB; an Irish site
in English needs en_IE. Use the underscore, a lower-case language and an upper-case country,
and use GB rather than UK. Write the answer for each language version down
before touching any settings.
Step 3
Fix the source of the value
Find
what feeds the tag instead of editing the tag. In WordPress, set the site language under Settings, General,
to English (UK) so Yoast or Rank Math print en_GB. In other systems, correct the language
or market setting, or the translation plugin's configuration for each language. Only hard-code a value
in a single-language site's template if nothing else sets it, and never in a layout that serves several
languages.
Step 4
Convert the format in one place
If
the stored value is in the hyphen form used by the lang attribute, add one conversion function
that swaps the hyphen for an underscore, fixes the case, replaces UK with GB
and adds your chosen country when only a language is stored. Use that function wherever og:locale
or og:locale:alternate is printed, so no template does its own conversion and gets it slightly
different.
Step 5
Add alternates only where they apply
List og:locale:alternate values only when the same address can serve the content
in another language. If each language lives at its own address, give each page its own primary og:locale
and connect the versions with hreflang instead. Remove any alternates for languages the
site does not actually offer, and never repeat the primary locale as an alternate of itself on the same
page.
Step 6
Check it agrees with the lang attribute
Purge
the page cache and reload the source. The lang attribute and og:locale should
describe the same language and country in their own formats, such as en-GB and en_GB.
Run the page through the generator again to confirm the locale is accepted, then check one page in each
other language to confirm each carries its own locale rather than the default.
When og:locale:alternate belongs in the block
The protocol describes og:locale:alternate as an array of other locales the page is available
in. Read literally, that means the same address, not a translation somewhere else. It suits a small number
of set-ups.
| Set-up | og:locale | og:locale:alternate |
|---|---|---|
| English-only site | en_GB | None |
English and Welsh at separate addresses (/cy/โฆ) | Each page declares its own:
en_GB or cy_GB | None; use hreflang to link the pair |
| One address that switches language by a cookie or header | The default language served | Each other language that address can serve |
| A bilingual page with both languages side by side | The main language | The second language |
<meta property="og:locale" content="en_GB">
<meta property="og:locale:alternate" content="cy_GB">
Each alternate gets its own tag; do not put a comma-separated list in one content attribute.
Order does not carry meaning, but keep the primary og:locale first so the block is easy
to read.
Edge cases
- Content for several English-speaking countries. If one English page serves the UK,
Ireland and Australia equally, pick the variety it is written in, usually
en_GB. Do not listen_IEanden_AUas alternates; they are not different versions of the page. - Machine-translated pages. Declare the language the visitor actually receives. A page translated in the browser by a script is still, as far as crawlers are concerned, the original language.
- Platform-specific codes. Some platforms keep their own list of locales and may not
recognise every combination. Stick to common language and country pairs for the primary value rather
than inventing combinations such as
cy_US. - Two sources printing the tag. A translation plugin and an SEO plugin may each print
og:locale. Readers normally take the first, so the page can declare the wrong language even though a correct tag is further down. Keep one source. - Staging and default installs. A fresh install or a restored backup can quietly reset the site language. Check the locale after migrations.
For the relationship between language versions in search, see fixing
hreflang and canonical conflicts. Each language page's og:url should name that language's
own address, as explained in fixing og:url and
canonical mismatches.
Keeping the locale right
- Record the site language decision. Note the chosen primary locale and each language version's locale in your site documentation, so the next developer or agency does not reset it.
- Derive, never duplicate. Store the language once and let the
langattribute,hreflangandog:localeall be generated from it. - Test a page per language after updates. Plugin and theme updates occasionally change how the locale is printed. A quick source check on one page per language after each update is enough.
- Include the locale in automated checks. If you already test for core Open Graph
tags on deployment, add a rule that the locale matches the pattern of two lower-case letters, an underscore
and two upper-case letters, and is not
en_USon a British site.
1. What is the correct og:locale for a UK website?
For content written in British English it is en_GB, with a lower-case language code, an underscore and the upper-case country code. The country code for the United Kingdom is GB, not UK, so en_UK is invalid even though it looks natural. The same GB code covers England, Scotland, Wales and Northern Ireland; Welsh-language pages would use cy_GB and Scottish Gaelic pages gd_GB. If the tag is absent altogether, readers are told to assume en_US.
2. Why does my site say en_US when I am in the UK?
Usually because a language setting was left at its default. WordPress installs in English (United States) unless you choose otherwise, and SEO plugins such as Yoast and Rank Math build og:locale from that site language. Changing Settings, General, Site Language to English (UK) changes the tag to en_GB. Other platforms have a similar store or site language setting. Fixing the setting rather than the tag keeps everything that depends on it consistent.
3. Is og:locale the same as the html lang attribute?
They describe the same thing in different formats. The lang attribute uses the BCP 47 style with a hyphen, as in en-GB, and browsers and screen readers read it. The og:locale tag uses an underscore, as in en_GB, and sharing platforms read it. Both should describe the same language and country for a given page. The simplest approach is to store the language once and convert it into each format when the page is printed.
4. Does og:locale help my site rank in the UK?
No. Google does not use og:locale to decide which country to show a page in. Country and language targeting in search relies on hreflang annotations, the language of the content itself, the domain and other signals. og:locale is labelling for sharing platforms and other readers of Open Graph data. It is worth getting right because it is cheap and accurate labelling helps those systems, but it is not a lever for search visibility in any particular country.
5. Should I list every language my site offers in og:locale:alternate?
Only if the same address can serve all of them. The protocol describes alternates as other locales this page is available in. If each language has its own address, such as a Welsh page under a cy folder, each page should declare its own primary locale and the versions should be connected with hreflang. Listing languages that a page cannot actually show gives readers a false description and adds noise without any benefit.
6. Does a wrong og:locale stop my preview from showing?
Almost never. The major platforms display the title, description and image regardless of the declared locale, so a card with en_US on a British page looks exactly the same. That is why the locale is a lower-priority finding than a missing image or a wrong og:url. It is still worth fixing, because it is often a sign that a language setting is wrong, and that setting can also affect date formats, spelling and accessibility.
7. What locale should a bilingual English and Welsh page use?
If one page shows both languages together, declare the main language as og:locale, for example en_GB, and the second language as og:locale:alternate, cy_GB. If the site has separate English and Welsh pages, which is more common and easier for every kind of crawler, each page declares only its own language: en_GB on the English page and cy_GB on the Welsh one, with hreflang linking the two versions for search engines.
The OG / Twitter Tag Generator builds the Open Graph and X card block for your page, validates it against the requirements of Facebook, LinkedIn and X, predicts how the preview will render and flags every tag that is missing or invalid.
Open Open Graph Fixes โ