{"id":1942,"date":"2025-08-18T20:18:37","date_gmt":"2025-08-18T14:48:37","guid":{"rendered":"https:\/\/myfreeonlinetools.com\/blog\/?p=1942"},"modified":"2025-08-18T20:18:37","modified_gmt":"2025-08-18T14:48:37","slug":"how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php","status":"publish","type":"post","link":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/","title":{"rendered":"How to Dynamically Update the HTML Lang Attribute in WordPress Using functions.php"},"content":{"rendered":"<p>WordPress and dynamically update the <code data-start=\"64\" data-end=\"80\">&lt;html lang=\"\"&gt;<\/code> attribute for <strong data-start=\"95\" data-end=\"106\">English<\/strong> and <strong data-start=\"111\" data-end=\"121\">French<\/strong> pages by editing your <strong data-start=\"144\" data-end=\"161\">functions.php<\/strong> file.<\/p>\n<p>&nbsp;<\/p>\n<pre>function swigroup_custom_language_attributes( $output ) {\r\n\/\/ Get the current URL\r\n$url_path = $_SERVER['REQUEST_URI'];\r\n\r\n\/\/ Default language\r\n$lang = 'en-US';\r\n\r\n\/\/ If URL contains \/fr\/, set lang to French\r\nif ( strpos( $url_path, '\/fr\/' ) !== false ) {\r\n$lang = 'fr-FR';\r\n}\r\n\r\n\/\/ Return the full attribute\r\nreturn 'lang=\"' . esc_attr( $lang ) . '\"';\r\n}\r\nadd_filter( 'language_attributes', 'swigroup_custom_language_attributes' );\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>WordPress and dynamically update the &lt;html lang=&#8221;&#8221;&gt; attribute for English and French pages by editing your functions.php file. &nbsp; function swigroup_custom_language_attributes( $output ) { \/\/ Get the current URL $url_path [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[29,24],"tags":[],"class_list":["post-1942","post","type-post","status-publish","format-standard","hentry","category-php","category-wordpress"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Dynamically Update the HTML Lang Attribute in WordPress<\/title>\n<meta name=\"description\" content=\"Learn dynamically change the attribute in WordPress by adding a simple PHP function in your theme\u2019s functions.php file. Perfect for multilingual sites (English, French, etc.) to improve SEO and accessibility.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Dynamically Update the HTML Lang Attribute in WordPress\" \/>\n<meta property=\"og:description\" content=\"Learn dynamically change the attribute in WordPress by adding a simple PHP function in your theme\u2019s functions.php file. Perfect for multilingual sites (English, French, etc.) to improve SEO and accessibility.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/\" \/>\n<meta property=\"og:site_name\" content=\"MyFreeOnlineTools\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/LearnSchoolOnline\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-18T14:48:37+00:00\" \/>\n<meta name=\"author\" content=\"myfreeonlinetools\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"myfreeonlinetools\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/\"},\"author\":{\"name\":\"myfreeonlinetools\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c\"},\"headline\":\"How to Dynamically Update the HTML Lang Attribute in WordPress Using functions.php\",\"datePublished\":\"2025-08-18T14:48:37+00:00\",\"dateModified\":\"2025-08-18T14:48:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/\"},\"wordCount\":31,\"publisher\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#organization\"},\"articleSection\":[\"PHP\",\"Wordpress\"],\"inLanguage\":\"en\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/\",\"name\":\"How to Dynamically Update the HTML Lang Attribute in WordPress\",\"isPartOf\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#website\"},\"datePublished\":\"2025-08-18T14:48:37+00:00\",\"dateModified\":\"2025-08-18T14:48:37+00:00\",\"description\":\"Learn dynamically change the attribute in WordPress by adding a simple PHP function in your theme\u2019s functions.php file. Perfect for multilingual sites (English, French, etc.) to improve SEO and accessibility.\",\"breadcrumb\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/#breadcrumb\"},\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/myfreeonlinetools.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Dynamically Update the HTML Lang Attribute in WordPress Using functions.php\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#website\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/\",\"name\":\"MyFreeOnlineTools\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/myfreeonlinetools.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#organization\",\"name\":\"MyFreeOnlineTools\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png\",\"contentUrl\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png\",\"width\":387,\"height\":79,\"caption\":\"MyFreeOnlineTools\"},\"image\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c\",\"name\":\"myfreeonlinetools\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g\",\"caption\":\"myfreeonlinetools\"},\"description\":\"Live in Delhi, Working in Gurgaon as Web Designer and Graphic Designer. Developed and Design myfreeonlinetools for online free tools. Also having youtube channel Name with LearnSchoolOnline. Traveling, watching movies, coding are the hobbies.\",\"sameAs\":[\"https:\/\/myfreeonlinetools.com\/\",\"https:\/\/www.facebook.com\/LearnSchoolOnline\/\",\"https:\/\/www.youtube.com\/learnschoolonline\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Dynamically Update the HTML Lang Attribute in WordPress","description":"Learn dynamically change the attribute in WordPress by adding a simple PHP function in your theme\u2019s functions.php file. Perfect for multilingual sites (English, French, etc.) to improve SEO and accessibility.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/","og_locale":"en_US","og_type":"article","og_title":"How to Dynamically Update the HTML Lang Attribute in WordPress","og_description":"Learn dynamically change the attribute in WordPress by adding a simple PHP function in your theme\u2019s functions.php file. Perfect for multilingual sites (English, French, etc.) to improve SEO and accessibility.","og_url":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/","og_site_name":"MyFreeOnlineTools","article_author":"https:\/\/www.facebook.com\/LearnSchoolOnline\/","article_published_time":"2025-08-18T14:48:37+00:00","author":"myfreeonlinetools","twitter_card":"summary_large_image","twitter_misc":{"Written by":"myfreeonlinetools","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/#article","isPartOf":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/"},"author":{"name":"myfreeonlinetools","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c"},"headline":"How to Dynamically Update the HTML Lang Attribute in WordPress Using functions.php","datePublished":"2025-08-18T14:48:37+00:00","dateModified":"2025-08-18T14:48:37+00:00","mainEntityOfPage":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/"},"wordCount":31,"publisher":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#organization"},"articleSection":["PHP","Wordpress"],"inLanguage":"en"},{"@type":"WebPage","@id":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/","url":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/","name":"How to Dynamically Update the HTML Lang Attribute in WordPress","isPartOf":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#website"},"datePublished":"2025-08-18T14:48:37+00:00","dateModified":"2025-08-18T14:48:37+00:00","description":"Learn dynamically change the attribute in WordPress by adding a simple PHP function in your theme\u2019s functions.php file. Perfect for multilingual sites (English, French, etc.) to improve SEO and accessibility.","breadcrumb":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/myfreeonlinetools.com\/blog\/how-to-dynamically-update-the-html-lang-attribute-in-wordpress-using-functions-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/myfreeonlinetools.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Dynamically Update the HTML Lang Attribute in WordPress Using functions.php"}]},{"@type":"WebSite","@id":"https:\/\/myfreeonlinetools.com\/blog\/#website","url":"https:\/\/myfreeonlinetools.com\/blog\/","name":"MyFreeOnlineTools","description":"","publisher":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/myfreeonlinetools.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/myfreeonlinetools.com\/blog\/#organization","name":"MyFreeOnlineTools","url":"https:\/\/myfreeonlinetools.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png","contentUrl":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png","width":387,"height":79,"caption":"MyFreeOnlineTools"},"image":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c","name":"myfreeonlinetools","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g","caption":"myfreeonlinetools"},"description":"Live in Delhi, Working in Gurgaon as Web Designer and Graphic Designer. Developed and Design myfreeonlinetools for online free tools. Also having youtube channel Name with LearnSchoolOnline. Traveling, watching movies, coding are the hobbies.","sameAs":["https:\/\/myfreeonlinetools.com\/","https:\/\/www.facebook.com\/LearnSchoolOnline\/","https:\/\/www.youtube.com\/learnschoolonline"]}]}},"_links":{"self":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/comments?post=1942"}],"version-history":[{"count":1,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1942\/revisions"}],"predecessor-version":[{"id":1943,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1942\/revisions\/1943"}],"wp:attachment":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/media?parent=1942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/categories?post=1942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/tags?post=1942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}