我有一个包含以下元素的 WordPress 模板:
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes('xhtml'); ?>>
这将返回:
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en-US">
不幸的是,“lang”属性在 XHTML 1.1 中是无效的——并且客户端想要这种级别的验证。
WordPress 的 general-template.php 文件包含以下代码:
if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
$attributes[] = "lang=\"$lang\"";
$doctype
是传递给它的参数(在本例中为“xhtml”)。应该get_option
返回“text/html”以外的值吗?如果是这样,我应该在 WordPress 中设置什么来实现这一点 - 如果有的话?
我也尝试使用 preg_replace 取出“lang”属性,但这似乎无法匹配文本。如果我手动输入文本,它匹配!可能是 language_attributes 返回的字符串的编码问题?