get_language_attributes()

Gets the language attributes for the ‘html’ tag.


Description

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


Return

(string) A space-separated list of language attributes.


Source

File: wp-includes/general-template.php

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

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

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

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

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

	/**
	 * Filters the language attributes for display in the html tag.
	 *
	 * @since WP-2.5.0
	 * @since WP-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 );
}


Changelog

Changelog
Version Description
4.3.0 Introduced.