Php 如何让WordPress language_attributes函数返回有效的XHTML1.1?

Php 如何让WordPress language_attributes函数返回有效的XHTML1.1?,php,wordpress,w3c-validation,xml-attribute,xhtml-1.1,Php,Wordpress,W3c Validation,Xml Attribute,Xhtml 1.1,我有一个WordPress模板,其中包含以下元素: <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes('xhtml'); ?>> $doctype是传递给它的参数(在本例中为“xhtml”)。get_option是否应返回除“text/html”以外的值?如果是这样,我应该在WordPress中设置什么来实现这一点呢 我还尝试使用preg_replace删除“lang”属性,但这似乎

我有一个WordPress模板,其中包含以下元素:

<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes('xhtml'); ?>>
$doctype
是传递给它的参数(在本例中为“xhtml”)。
get_option
是否应返回除“text/html”以外的值?如果是这样,我应该在WordPress中设置什么来实现这一点呢


我还尝试使用preg_replace删除“lang”属性,但这似乎与文本不匹配。如果我手动输入文本,它将匹配!语言属性返回的字符串可能存在编码问题

如果这只是您自己网站上的一个主题,您可以编辑header.php并更改

我解决了这个问题。有一个“language_attributes”过滤器,所以我编写了一个链接到该过滤器并执行一个简单的preg_替换。当在这里执行替换时,它起作用了,这是一种非常巧妙的处理方法

编辑

根据要求,以下是我使用的代码:

<?php
/*
Plugin Name: Create Valid XHTML 1.1
Plugin URI: http://www.mycompany.com/create_valid_xhtml_1_1
Description: Removes deprecated "lang" attribute from (X)HTML header.
Author: dommer
Version: 1.0.0
Author URI: http://www.mycompany.com
*/

function create_valid_xhtml_1_1($language_attributes) 
{
    return preg_replace('/ lang=\"[a-z]+\-[A-Z]+\"/', '', $language_attributes);
}

add_filter('language_attributes', 'create_valid_xhtml_1_1');
?>

这是一个选项。但我不确定客户端可能会将模板用于其他用途,因此,如果可以,我希望保留该功能。
if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
    $attributes[] = "lang=\"$lang\"";
<?php
/*
Plugin Name: Create Valid XHTML 1.1
Plugin URI: http://www.mycompany.com/create_valid_xhtml_1_1
Description: Removes deprecated "lang" attribute from (X)HTML header.
Author: dommer
Version: 1.0.0
Author URI: http://www.mycompany.com
*/

function create_valid_xhtml_1_1($language_attributes) 
{
    return preg_replace('/ lang=\"[a-z]+\-[A-Z]+\"/', '', $language_attributes);
}

add_filter('language_attributes', 'create_valid_xhtml_1_1');
?>