Do you think you may need to use our automated fix to add language and text direction attributes to your site’s HTML element? This article explains how to easily add lang and dir attributes to your WordPress site for improved accessibility.
How to fix lang and dir attributes in WordPress
If your website is missing language attributes, this can be easily fixed without writing code using the WordPress Accessibility Checker plugin.
Step 1
Click into the Accessibility Checker plugin settings in your WordPress dashboard (you must be logged in with an administrator account to access these settings).
Step 2
Go to the “Fixes” tab in the Settings Tabs navigation.
Step 3
Check the box for Add “lang” & “dir” Attributes, then scroll to the bottom of the page and click the “Save Changes” button.
Note: Automated accessibility fixes use JavaScript or other methods to modify how your website functions. Occasionally, a WordPress theme or extension may conflict with or prevent our fixes from working as expected. We recommend testing these fixes on a local or staging copy of your website first.
Not seeing the fix?
The Add “lang” & “dir” Attributes accessibility fix should start working immediately; however, if you don’t see the fix, it could be because you’re seeing a cached version of your website. Try clearing the cache in any caching plugins and on your hosting account, then look at your site in an incognito window to confirm the fix worked.
Note: Turning on a fix will not instantly remove related issues from Accessibility Checker reports. After turning on a fix, you can clear issues from reports by running a full site scan in Accessibility Checker Pro or by saving any individual post/page to trigger a rescan of that post/page only.
What This Fix Does
When enabled, the Add “lang” & “dir” Attributes fix first checks if the webpage has the language lang
and text direction dir
attributes in the HTML element. Here is an example of a valid HTML element with these attributes defined appropriately:
<html lang="en" dir="ltr">
If either of the language lang
and text direction dir
attributes are missing, the fix will define the missing attribute using available site information. The fix will attempt to retrieve this information using built-in WordPress functions get_bloginfo()
and is_rtl()
. If the fix cannot use the built-in method, it will use JavaScript as a fallback.
Existing language and text direction attributes will not be replaced.
Impact on Accessibility
The language attribute informs assistive technologies about the content’s primary language. Screen readers, for instance, rely on this information to correctly pronounce words and phrases, thus improving the experience for users with visual impairments. Without a language attribute, assistive tools may misinterpret the text, leading to a frustrating user experience.
The text direction attribute specifies the direction in which text should be read (left-to-right or right-to-left). For languages like Arabic or Hebrew, which are read right-to-left, the direction attribute ensures proper text alignment and flow. This is crucial for users who depend on the correct text direction to understand and interact with the content.
Associated Checks
The following checks in Accessibility Checker are associated with this fix: