Title: language_attributes
Published: August 18, 2015
Last modified: August 20, 2026

---

# apply_filters( ‘language_attributes’, string $output, string $doctype )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#user-contributed-notes)

Filters the language attributes for display in the ‘html’ tag.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#parameters)󠁿

 `$output`string

A space-separated list of language attributes.

`$doctype`string

The type of HTML document (`xhtml|html`).

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#source)󠁿

    ```php
    return apply_filters( 'language_attributes', $output, $doctype );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/general-template.php#L4776)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/general-template.php#L4776-L4776)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#related)󠁿

| Used by | Description | 
| [get_language_attributes()](https://developer.wordpress.org/reference/functions/get_language_attributes/)`wp-includes/general-template.php` |

Gets the language attributes for the ‘html’ tag.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Added the `$doctype` parameter. | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/language_attributes/?output_format=md#comment-content-6089)
 2.   [Guillaume TURPIN](https://profiles.wordpress.org/guillaumeturpin/)  [  4 years ago  ](https://developer.wordpress.org/reference/hooks/language_attributes/#comment-6089)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Flanguage_attributes%2F%23comment-6089)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Flanguage_attributes%2F%23comment-6089)
 4. Here is a function to force the locale of the HTML lang attribute without breaking
    the other attributes like dir
 5.     ```php
        /**
         * Forces the site locale for the HTML lang attribute.
         * 
         * @param string $locale the locale to set with the following format : "en-US"
         * @return void
         */
        function wpdocs_force_site_locale( $locale = 'en-US' ) {
        	add_filter( 'language_attributes', function( $output ) use ( $locale ) {
        		// match the lang attribute and replace it with the new locale
        		$lang_regex = '/lang="([a-zA-Z-_]+)"/';
        		$output     = preg_replace( $lang_regex, 'lang="' . $locale . '"', $output );
    
        		// update the xml:lang attribute as well
        		$xml_lang_regex = '/xml:lang="([a-zA-Z-_]+)"/';
        		$output         = preg_replace( $xml_lang_regex, 'xml:lang="' . $locale . '"', $output );
    
        		return $output;
        	} );
        }
        ```
    
 6.  * The second preg_replace is not necessary, the first preg_replace will have already
       changed it.
     * [Scott Thomason](https://profiles.wordpress.org/scott8035/) [3 years ago](https://developer.wordpress.org/reference/hooks/language_attributes/#comment-7009)
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Flanguage_attributes%2F%3Freplytocom%3D6089%23feedback-editor-6089)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Flanguage_attributes%2F)
before being able to contribute a note or feedback.