获取html标记的语言属性。
原型
get_language_attributes( string $doctype = 'html' )
描述
构建一组html属性,包含页面的文本方向和语言信息。
参数
$doctype
(string)
(Optional)
html文档的类型。接受’xhtml’或’html’。
源文件
路径:wp-includes/general-template.php
<?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 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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_language_attributes/