1

次の要素を含む 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 によって返される文字列のエンコーディングの問題でしょうか?

4

2 に答える 2

2

私はこれを解決しました。「language_attributes」フィルターがあるので、それにフックして単純なpreg_replaceを実行するプラグインを作成しました。ここで実行すると、置換が機能しました。これは、それを処理するための非常に優れた方法です。

編集

リクエストに応じて、使用したコードは次のとおりです。

<?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');
?>
于 2009-11-27T18:26:51.480 に答える
1

これが自分のサイトの単なるテーマである場合は、header.php を編集して、

<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes('xhtml'); ?>>

行をハードコーディングすると、パフォーマンスも向上します:-)

于 2009-11-26T23:44:14.697 に答える