A hreflang tag is a small piece of code that tells Google (and other search engines) which language or regional version of a page to show a visitor based on their browser language or location. If your website has separate English and Swahili versions of the same pages, hreflang tags help make sure a search user in Kenya sees the right one instead of Google picking the wrong version, or treating both versions as duplicate content.
When Do You Actually Need Hreflang Tags?
Not every website needs them. You only need hreflang tags if you publish the same content in more than one language on separate URLs, for example:
- A page at
/en/servicesand the same page translated at/sw/services - Separate subdomains, such as
en.example.co.keandsw.example.co.ke - Fully separate domains for each language
If your site is mostly in English with just the occasional Swahili phrase mixed in on the same page, you don't need hreflang tags at all. A language switcher without duplicate pages behind it also doesn't need them.
If you haven't built separate language versions of your pages yet, start with your overall language setup first. See the related article on adding a Swahili language switcher below before worrying about hreflang.
How to Add Hreflang Tags to Your Website
If You Use WordPress
The easiest route is a multilingual plugin, such as Polylang or WPML, which generates and manages hreflang tags for you automatically once you've set up your English and Swahili content as linked translations. You shouldn't need to touch any code:
- Install and activate a multilingual plugin from your WordPress dashboard under Plugins > Add New.
- Follow the plugin's setup wizard to add Swahili as a second language.
- Link each English page to its Swahili translation inside the plugin's translation screen.
- The plugin automatically inserts the correct hreflang tags into your site's
<head>section on every page that has a translation.
If You Have a Static HTML Website
Without a plugin, you add the tags manually inside the <head> section of each language version of the page. For a page that exists in both English and Swahili, both versions need the same set of tags, including a tag pointing to themselves:
<link rel="alternate" hreflang="en" href="https://example.co.ke/en/services" /> <link rel="alternate" hreflang="sw" href="https://example.co.ke/sw/services" /> <link rel="alternate" hreflang="x-default" href="https://example.co.ke/en/services" />
The x-default line tells Google which version to show a visitor whose language doesn't match any of the versions you've listed. You'd normally set this to your main (usually English) version. Use your File Manager or FTP client to edit the HTML file for each page and add these lines.
Common Mistakes to Avoid
- Missing the self-referencing tag. Every language version needs to list itself as well as the other versions, not just link to the other one.
- Tags that don't match on both sides. If your English page says the Swahili version is at a certain URL, that Swahili page needs to point right back at the English one. A one-way link confuses Google rather than helping it.
- Using the wrong language code. Swahili is
sw, notsw-KE, unless you're specifically targeting only Kenyan Swahili speakers as distinct from Swahili speakers elsewhere.
Once your tags are live, you can confirm Google is picking them up correctly through the International Targeting report in Google Search Console, which flags broken or mismatched hreflang pairs.
For the on-page basics that matter to every page, whether or not it has a translated version, see On-Page SEO Basics. If you still need to set up a Swahili version of your site in the first place, see How to Add a Swahili Language Switcher to Your Website.