Site Language

How to Change the HTML Language in WordPress

The HTML language attribute (lang) specifies the primary language used on your website. It’s declared in the <html> tag of your site’s source code. By default, WordPress sets this attribute to en-US (American English). If you check the page source of your WordPress website, you’ll likely see something like this:

<html lang="en-US">

If your website uses a language other than English, you might want to update this attribute to reflect your content’s language. While search engines like Google generally ignore this value, updating it is considered good practice for accessibility and adherence to web standards.

Changing the Language via the WordPress Dashboard

The easiest way to change the HTML language attribute is through the WordPress dashboard. Here’s how:

  1. Navigate to Settings > General.
  2. Locate the Site Language dropdown.
  3. Select your desired language from the list.
  4. Click Save Changes.
Site Language

If the selected language is available in WordPress, it will be automatically installed. Once saved, refresh your website and view its source code. You’ll see the updated lang attribute reflecting the chosen language.

Keeping the Dashboard Language in English

The above method is simple and effective, but it also changes the language of the WordPress dashboard. If you prefer to keep the dashboard in English while updating the lang attribute for the front end, you can achieve this by adding a small code snippet to your theme’s functions.php file:

add_filter('language_attributes', 'custom_lang_attr');
function custom_lang_attr() {
  return 'lang="bn-BD"';
}

Replace bn-BD with the language code of your choice. For example:

  • French: fr-FR
  • German: de-DE
  • Spanish: es-ES

After saving the file, refresh your website and check the page source to confirm the change.

Whether you’re localizing your site for a specific audience or adhering to best practices, updating the HTML language attribute is straightforward in WordPress. Choose the method that best suits your needs and ensure your website is optimized for all users.

Leave a Comment

Your email address will not be published. Required fields are marked *