Add Language Code to WordPress Homepage URL
In this article
Adding a language code (like /en/ or /fr/) to your WordPress homepage URL lets you serve localized versions of your site from distinct addresses. This is useful for multilingual sites, A/B testing, or geo-targeting. You can do this with a plugin or by editing your site's .htaccess file. Below is a practical, step-by-step guide.
What You'll Need
- Admin access to your WordPress dashboard.
- FTP or cPanel file manager access (for the manual method).
- A backup of your site (files and database) before making changes.
Step-by-Step
Method 1: Using a Plugin (Recommended for Most Users)
- Install a multilingual plugin like Polylang, WPML, or TranslatePress. These plugins automatically add language codes to URLs, including the homepage.
- Go to Plugins → Add New in your WordPress admin. Search for your chosen plugin, install, and activate it.
- Configure the plugin's language settings. For Polylang, go to Languages → Settings. For WPML, go to WPML → Languages. For TranslatePress, go to Settings → TranslatePress.
- Add your languages. Choose the languages you want (e.g., English, French). The plugin will assign a language code (like
enorfr) to each. - Set the URL format. In the plugin settings, look for “URL modifications” or “Language URL format.” Select “Use language code in URL” or “Different languages in directories” (e.g.,
example.com/en/). - Save changes. The plugin will add the language code to your homepage URL automatically. For example,
example.combecomesexample.com/en/for English.
Method 2: Manual .htaccess Redirect (For a Single Language Prefix)
- Back up your .htaccess file. Connect to your server via FTP or cPanel File Manager. Download the
.htaccessfile from your WordPress root directory. - Open the .htaccess file in a plain text editor (like Notepad).
- Add a redirect rule at the top. Insert the following code, replacing
enwith your desired language code andexample.comwith your domain:RewriteEngine On RewriteRule ^$ /en/ [R=301,L]
- Save the file and upload it back to your server, overwriting the original.
- Test the homepage. Visit your domain. It should redirect to
example.com/en/.
Method 3: Using a Custom Page as a Static Front Page
- Create a new page in WordPress (Pages → Add New). Name it “Home” or “English Home.”
- Set the page slug to
en(or your language code) in the page editor's permalink settings. - Go to Settings → Reading in the admin.
- Under “Your homepage displays,” select “A static page.”
- Choose the “Home” page you just created from the “Homepage” dropdown.
- Save changes. Your homepage URL will now be
example.com/en/.
Common Mistakes
- Forgetting to update internal links: After changing the homepage URL, update any hardcoded links in menus, widgets, or content that point to the old URL.
- Not using 301 redirects: If you change the URL structure, always use 301 redirects from the old URL to the new one to preserve SEO and avoid broken links.
- Editing .htaccess without a backup: A syntax error can break your entire site. Always keep a backup and test locally if possible.
- Using a plugin that conflicts with your theme: Some multilingual plugins require specific theme compatibility. Check the plugin's documentation.
Tips
- Use a plugin for multiple languages: If you need more than one language, a plugin is far easier and more reliable than manual edits.
- Set the language code as the default: In plugin settings, you can often set the primary language to appear without a prefix (e.g.,
example.comfor English) and others with prefixes. This is cleaner for your main audience. - Update your sitemap: After the change, regenerate your XML sitemap and submit it to Google Search Console so search engines crawl the new URLs.
- Test on a staging site first: If you're not comfortable with code, test the change on a staging copy of your site before going live.
Troubleshooting
- Homepage shows 404 error: This usually means the redirect or page slug is incorrect. Check that the page exists and the slug matches the language code. If using .htaccess, ensure the rule is placed before any other rules.
- Redirect loop: If you get a “too many redirects” error, you may have conflicting rules. Remove any other redirects that affect the root URL, and clear your browser cache.
- Plugin not adding the code: Some plugins require you to set the language for the homepage specifically. In Polylang, go to Languages → Settings and ensure “Hide URL language information for default language” is unchecked if you want the code on the default language.
- Changes not showing: Clear your browser cache and any caching plugin (like WP Super Cache or W3 Total Cache). Also, check if your hosting provider has server-side caching.
- After manual .htaccess edit, site is down: Restore the backup .htaccess file immediately. Then, try the plugin method instead.
Frequently Asked Questions
Will adding a language code affect my SEO?
If done with proper 301 redirects and hreflang tags (which multilingual plugins add automatically), it can improve SEO by clearly separating language versions. Without redirects, you risk duplicate content issues.
Can I have the homepage without a language code?
Yes. Most plugins let you set the default language to appear without a prefix. For example, example.com could be English, and example.com/fr/ for French.
Does this work with any WordPress theme?
Yes, the URL structure is independent of your theme. However, some themes have built-in multilingual support that may conflict with plugins. Test on a staging site if unsure.
What if I only want to add a language code to the homepage, not other pages?
That's unusual, but you can achieve it with the manual .htaccess method. However, it's not recommended because it can confuse users and search engines. Better to use consistent URL structure across the site.
Will my existing homepage content be lost?
No. The content remains in the database. If you use a static page method, you'll need to copy the content to the new page. With a plugin, the existing content is preserved and assigned to the default language.
Can I change the language code later?
Yes, but you'll need to update all URLs and set up redirects from the old codes to new ones. Plugins make this easier, but it's still a significant change.