get_language_attributes

Gets the language attributes for the html tag.

Description

get_language_attributes( (string) $doctype = 'html' ); 

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

Parameters (1)

0. $doctype — Optional. (string) => 'html'
The type of html document. Accepts xhtml or html.. Default html..

Usage

  1. if ( !function_exists( 'get_language_attributes' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'. 
  5. $doctype = 'html'; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_language_attributes($doctype); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function get_language_attributes( $doctype = 'html' ) { 
  2. $attributes = array(); 
  3.  
  4. if ( function_exists( 'is_rtl' ) && is_rtl() ) 
  5. $attributes[] = 'dir="rtl"'; 
  6.  
  7. if ( $lang = get_bloginfo('language') ) { 
  8. if ( get_option('html_type') == 'text/html' || $doctype == 'html' ) 
  9. $attributes[] = "lang=\"$lang\""; 
  10.  
  11. if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' ) 
  12. $attributes[] = "xml:lang=\"$lang\""; 
  13.  
  14. $output = implode(' ', $attributes); 
  15.  
  16. /** 
  17. * Filters the language attributes for display in the html tag. 
  18. * @since 2.5.0 
  19. * @since 4.3.0 Added the `$doctype` parameter. 
  20. * @param string $output A space-separated list of language attributes. 
  21. * @param string $doctype The type of html document (xhtml|html). 
  22. */ 
  23. return apply_filters( 'language_attributes', $output, $doctype );