Title: get_language_attributes
Published: August 18, 2015
Last modified: February 24, 2026

---

# get_language_attributes( string $doctype ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#wp--skip-link--target)

Gets the language attributes for the ‘html’ tag.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#description)󠁿

Builds up a set of HTML attributes containing the text direction and language information
for the page.

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

 `$doctype`stringoptional

The type of HTML document. Accepts `'xhtml'` or `'html'`. Default `'html'`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#return)󠁿

 string A space-separated list of language attributes.

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

    ```php
    function get_language_attributes( $doctype = 'html' ) {
    	$attributes = array();

    	if ( function_exists( 'is_rtl' ) && is_rtl() ) {
    		$attributes[] = 'dir="rtl"';
    	}

    	$lang = get_bloginfo( 'language' );
    	if ( $lang ) {
    		if ( 'text/html' === get_option( 'html_type' ) || 'html' === $doctype ) {
    			$attributes[] = 'lang="' . esc_attr( $lang ) . '"';
    		}

    		if ( 'text/html' !== get_option( 'html_type' ) || 'xhtml' === $doctype ) {
    			$attributes[] = 'xml:lang="' . esc_attr( $lang ) . '"';
    		}
    	}

    	$output = implode( ' ', $attributes );

    	/**
    	 * Filters the language attributes for display in the 'html' tag.
    	 *
    	 * @since 2.5.0
    	 * @since 4.3.0 Added the `$doctype` parameter.
    	 *
    	 * @param string $output A space-separated list of language attributes.
    	 * @param string $doctype The type of HTML document (xhtml|html).
    	 */
    	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/6.9.4/src/wp-includes/general-template.php#L4516)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/general-template.php#L4516-L4546)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#hooks)󠁿

 [apply_filters( ‘language_attributes’, string $output, string $doctype )](https://developer.wordpress.org/reference/hooks/language_attributes/)

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

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

| Uses | Description | 
| [is_rtl()](https://developer.wordpress.org/reference/functions/is_rtl/)`wp-includes/l10n.php` |

Determines whether the current locale is right-to-left (RTL).

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

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

Retrieves information about the current site.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_language_attributes/?output_format=md#)

| Used by | Description | 
| [WP_Sitemaps_Stylesheet::get_sitemap_stylesheet()](https://developer.wordpress.org/reference/classes/wp_sitemaps_stylesheet/get_sitemap_stylesheet/)`wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php` |

Returns the escaped XSL for all sitemaps, except index.

  | 
| [WP_Sitemaps_Stylesheet::get_sitemap_index_stylesheet()](https://developer.wordpress.org/reference/classes/wp_sitemaps_stylesheet/get_sitemap_index_stylesheet/)`wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php` |

Returns the escaped XSL for the index sitemaps.

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

Displays the language attributes for the ‘html’ tag.

  | 
| [_default_wp_die_handler()](https://developer.wordpress.org/reference/functions/_default_wp_die_handler/)`wp-includes/functions.php` |

Kills WordPress execution and displays HTML page with an error message.

  |

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

| Version | Description | 
| [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |

## User Contributed Notes

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