유효한 XHTML 1.1을 반환하기 위해 WordPress Language_Attributes 기능을 얻으려면 어떻게해야합니까?

StackOverflow https://stackoverflow.com/questions/1805718

문제

다음 요소가 포함 된 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에 의해 문자열이 반환되는 인코딩 문제 일 수 있습니까?

도움이 되었습니까?

해결책

나는 이것을 해결했다. "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');
?>

다른 팁

이것이 자신의 사이트에있는 테마 일 경우 Header.php를 편집하고 변경할 수 있습니다.

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

하드 코딩 된 라인은 성능을 향상시킵니다 :-)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top