To ensure that your content is being served to correct language speakers, you can declare the language that your content is written in using your
<html> tag in your header.
In this article, you’ll learn how to declare the language of your content in your
<html> tag as well as declaring more than one language.
How to Declare a Language Tag
Declaring the language that your content is in is rather important considering the fact that your users won’t be able to read it unless it is served in the correct language. With that in mind, you should always declare the language of your site to ensure that the visitors you’re getting are able to interact with your content.
Accessing your Header.php in WordPress
First of all, you need to be able to access the source code of your website. We’re going to teach how to do that in WordPress, but it shouldn’t be hard to find if you have another provider.
First, navigate to the backend of your site and, using the left sidebar, select Appearance > Editor.
On the right side, click header.php.
Right at the top of the code, you should see your
<html> tag. That’s what we’ll be editing. Now we just need to choose the right language.
Different Language Tags
Each language tag that you add to the
<html> tag will include the language code and has the option of including a region code. These regions are useful for languages like Spanish that differ greatly based on where it is spoken.
The best list that we’ve found is provided by Microsoft, but you can find some common ones listed below.
|en-US||English – United States|
|en-GB||English – United Kingdom|
|es-PR||Spanish – Puerto Rico|
|es-ES||Spanish – Spain|
The format to input these codes into your
<html> tag is as follows:
Simply fill in the code with the correct language code and update your header.php file.
Managing a Multi-language Website?
I have good news, bad news, and then more good news.
The good news is you’re awesome for being multilingual.
The bad news is you aren’t able to list two languages in your
<html> tag, such as
<html lang="en-GB, es-ES">. It simply won’t accept it.
Also, it’s not advised to simply have a different URL for each language that you have on your site. That can create duplicate content issues.
Don’t worry because here’s good news too – We recommend using a plugin that will automatically implement hreflang tags across your website. So you’ll have more time to learn more languages.
Polylang is a free plugin for WordPress that allows you to set different languages for your website. Then, you simply tag the posts with the language that the content is written in and Polylang handles all of the technical hreflang work for you. You reap all of the benefits without writing a single line of code.