On this page
get_language_attributes( string $doctype = 'html' ): string
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.
Parameters
$doctypestring Optional-
The type of HTML document. Accepts
'xhtml'or'html'. Default'html'.Default:
'html'
Return
string A space-separated list of language attributes.
Source
File: wp-includes/general-template.php. View all references
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 );
}
Hooks
- apply_filters( 'language_attributes',
string $output ,string $doctype ) -
Filters the language attributes for display in the ‘html’ tag.
Related
Uses
| Uses | Description |
|---|---|
| is_rtl() wp-includes/l10n.php | Determines whether the current locale is right-to-left (RTL). |
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
| get_bloginfo() wp-includes/general-template.php | Retrieves information about the current site. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
Used By
| Used By | Description |
|---|---|
| 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() wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php | Returns the escaped XSL for the index sitemaps. |
| language_attributes() wp-includes/general-template.php | Displays the language attributes for the ‘html’ tag. |
| _default_wp_die_handler() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_language_attributes