language_attributes()
云策文档标注
概述
language_attributes() 是一个 WordPress 函数,用于在 HTML 标签中输出语言属性,包括文本方向和语言信息。它作为 get_language_attributes() 的包装器,简化了在主题或插件中的使用。
关键要点
- 函数功能:输出 HTML 标签的语言属性,如 lang 和 dir,以支持多语言和文本方向。
- 参数:$doctype 可选,指定 HTML 文档类型,接受 'xhtml' 或 'html',默认值为 'html'。
- 实现方式:内部调用 get_language_attributes() 函数生成属性字符串,然后直接输出。
- 相关函数:与 get_language_attributes() 紧密关联,后者用于获取属性字符串而不输出。
- 使用场景:常用于主题的 header.php 文件或插件中,确保页面语言设置正确。
- 版本历史:自 WordPress 2.1.0 引入,4.3.0 版本重构为包装器函数。
代码示例
<html <?php language_attributes(); ?>>注意事项
- 确保在 HTML 标签中正确调用,以输出有效的 lang 和 dir 属性。
- 参数 $doctype 影响输出格式,需根据文档类型选择 'xhtml' 或 'html'。
- 函数直接输出结果,无返回值,适用于 echo 场景;如需获取字符串,请使用 get_language_attributes()。
原文内容
Displays 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
$doctypestringoptional-
The type of HTML document. Accepts
'xhtml'or'html'. Default'html'.
Source
function language_attributes( $doctype = 'html' ) {
echo get_language_attributes( $doctype );
}
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Converted into a wrapper for get_language_attributes() . |
| 2.1.0 | Introduced. |
Skip to note 2 content
Codex
Example
<html <?php language_attributes(); ?>> <head> ...(from wp-content/themes/twentyten/header.php)