WordPress에서 마크 업 (예 : HTML5 또는 HTML4)에 대한 자체 폐쇄 태그를 끄려면 어떻게해야합니까?


18

WordPress 테마에서 HTML5를 사용하고 싶습니다. wptexturize를 끄려면 어떻게해야합니까?

나는 WP가 나누기를 추가하는 것을 신경 쓰지 않지만 나는 그렇게하고 싶지 <br>않습니다 <br />. 코드에서 이러한 구분이 표시되는 방식을 제어하려면 어떻게해야합니까?

편집 : 나는 <br>태그 문제 에만 관심이 있으며 인쇄상의 변경 사항은 신경 쓰지 않습니다.

EDIT2 : 실제로 <img>태그도 중요하다고 생각 합니다. 자체 폐쇄 독립형 태그가 여기에 중요합니다. 따라서 <hr>문제가 될 수도 있습니다. 다양한 태그 와 같은 wp_head()항목은 말할 것도 없습니다 .<link><meta>


1
무슨 일이야 <br />?
Scott M.

2
괜찮지 만 비 XML 버전의 HTML5로 헷갈 리려면 XML 스타일의`/>`엔딩을 원하지 않습니다.
artlung

<br />이 유효한 html 및 xhtml이라고 생각 했습니까? 언제 아니 었어?
Ryan Gibbons

5
나는이 질문이 매우 잘못된 것이라고 생각합니다. wptexturize는 어떤 식 으로든 사이트가 HTML 5를 준수하지 못하게하지 않습니다.
Ryan Gibbons

2
"워드 프레스 생성 마크 업의 자동 닫는 요소에서 후행 슬래시를 제거하려면 어떻게해야합니까?"
Bobby Jack

답변:


21

줄 바꿈은가 wpautop()아닌 에 의해 추가됩니다 wptexturize(). wpautop()단락 태그를 자동으로 추가하는 기능이기도합니다.

<br />필터를 교체하는 것보다를 고정하는 것이 좋습니다 . wpautop()우선 순위 10으로 실행 되므로 이후에 연결하여 수정할 수 있습니다.

add_filter( 'the_content', 'html5_line_breaks', 25 );

function html5_line_breaks( $content ) {
    return str_replace( '<br />', '<br>', $content );
}

OP 업데이트 후 편집 :

워드 프레스 기능은 XHTML을 출력하도록 설계되었습니다. 사이트 전체에서 슬래시를 제거하려면 출력 버퍼를 사용해야합니다. 게시물 내용에서 슬래시를 대체하기 위해 위의 필터와 유사한 필터를 사용할 수 있지만 헤드, 사이드 바 등을 잡을 수는 없습니다.

약간 추악하고 성능에 약간의 영향을 줄 수 있지만 여기에 있습니다 (플러그인 또는 테마 functions.php파일에 놓으십시오 ).

if ( !is_admin() && ( ! defined('DOING_AJAX') || ( defined('DOING_AJAX') && ! DOING_AJAX ) ) ) {
    ob_start( 'html5_slash_fixer' );
    add_action( 'shutdown', 'html5_slash_fixer_flush' );
}

function html5_slash_fixer( $buffer ) {
    return str_replace( ' />', '>', $buffer );
}

function html5_slash_fixer_flush() {
    ob_end_flush();
}

이 코드는 관리 영역에 있지 않고 AJAX 요청 처리를 수행하지 않으면 필터를 통해 출력 버퍼링을 시작한 다음 WordPress 종료 후크를 사용하여 해당 버퍼를 출력한다고 말합니다.


아직 열려있는 functions.php를 해독 할 시간이 없었지만 블록이가는 곳을 자세히 설명 할 수 있습니까? 일단 해당 파일을 열 기회가 생기면 분명 할 수 있지만, 문제를 해결할 수있을 것이라고 생각합니다.
토마스 오웬스

@Thomas : 테마 functions.php파일은 플러그인 파일과 같습니다. 거기에있는 모든 코드가 자동으로 실행됩니다. 유효한 PHP 인 한 어디로 가는지는 중요하지 않습니다.
Viper007Bond

아 흥미 롭군 저는 WordPress 개발에 익숙하지 않아서 여전히 많은 것을 배우고 있습니다. 정리해 주셔서 감사합니다.
토마스 오웬스

8

여기 있습니다 :

function my_awesome_tag_fixer( $input ){
  return preg_replace( '/(<.+)\s\/>/', '$1>', $input );
}

foreach( array('the_content', 'the_excerpt', 'comment_text') as $filter )
  add_filter( $filter, 'my_awesome_tag_fixer', 12 );

가장 우아한 솔루션은 아니지만 wpautop 및 wptexturize를 다시 작성하는 것보다 훨씬 빨리 완료됩니다.


1
+1 HTML 4.01 엄격한 규정 준수와 매우 유사한 작업을 수행했습니다.
Trevor Bramble

7

방금 찾았습니다. void 요소의 자체 닫는 태그는 유효한 html입니다.

In HTML5 we've allowed the / on void elements (like <meta>, <img>, <br>, <input>, etc), to ease migration to and from XML.

http://lists.whatwg.org/pipermail/help-whatwg.org/2008-August/000137.html

더 많은 정보 :

http://wiki.whatwg.org/wiki/FAQ#Should_I_close_empty_elements_with_.2F.3E_or_.3E.3F


1
"그러나 XHTML1을 광범위하게 사용하려는 시도로 인해 후행 슬래시를 사용하는 페이지 수가 상당히 많습니다. 이로 인해 XHTML1에서 HTML5로 쉽게 마이그레이션 할 수 있도록 HTML의 void 요소에 후행 슬래시 구문이 허용되었습니다. " 레거시로 허용됩니다. 앞으로 나아갈 길은 여분의 "/"를 버리고 있다고 생각합니다. WordPress가 xhtml, html4.01 또는 html5에 코드를 작성하는 옵션을 허용해야한다고 생각합니다.
artlung

그것은 당신이 말하는 것을 읽는 문제입니다. 후행 슬래시가 허용되므로 유효한 구문입니다. 당신은 그것이 제거 될 것이라고 추측하고 있습니까? 표준이 어디로 가고 있는지 추측하고 존재하지 않는 문제를 해결하기위한 작업을 만드는 이유는 무엇입니까?
Ryan Gibbons

나는 아무것도 추측하지 않습니다. 나는 아무것도 추측하지 않습니다. / 마크는 사양에 필요하지 않으며 WordPress에서 제거 할 수있는 옵션이 필요합니다.
artlung

나는 XHTML을 좋아한다. 우리는 오래된 HTML의 무질서한 모습으로 돌아 가야만 하는가?
Arlen Beiler

알렌, 나는 질서 정연한 HTML을 좋아한다. 나는 xhtml을 좋아한다. 나는 검증 인들의 열렬한 팬입니다. 내 자신의 코드에서 유효성 검사를 수행하기 위해 내 자신의 doctype을 작성했습니다. html 3.2, html 4, 4.01, 심지어 html 2.0을 사용했습니다! lab.artlung.com/html-2.0-WordPress에서 자체 닫는 태그를 제거하는 옵션을 원합니다. 그렇게 큰 일이 아닌 것 같습니다. 내 질문의 전제로 논쟁하는 것이 매우 도움이되지 않습니다.
artlung

6

예를 들어 테마를 사용하여 테마의 function.php 파일 에서 비활성화 할 수 있습니다 remove_filter()(http://codex.wordpress.org/Function_Reference/remove_filter)

remove_filter("the_content", "wptexturize");

1
이것에 대해 더 세밀하게 제어 할 수 있습니까? 이렇게하면 인쇄 상이 없어지지 않습니까?
artlung

나는 머리 꼭대기에서 간단한 접근 방법을 알지 못하지만 내가 당신을 위해 무엇을 알아낼 수 있는지 보자.
thomasjo

에서 찾은 원하는 기능을 재현 wptexturize()하지 못한 다른 가능한 솔루션을 찾을 수 없었습니다.
thomasjo

단순히 반대로 <br />바꿀 수있는 방법이 있는지 궁금합니다 <br>.
artlung

5

html5 및 WordPress의 초보자 테마와 wptexturize가 아닌 wpautop () 용 함수가 있습니다. 따로, 또는 다른 HTML 요소, THEAD 같은 TFOOT 포함하고 HTML5 같은 구문을 사용
하고

/**
 * wpautop for HTML5, allowed: table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr|fieldset|legend|section|article|aside|header|footer|hgroup|figure|details|figcaption|summary)
 * @link http://nicolasgallagher.com/using-html5-elements-in-wordpress-post-content/
 * @author nicolas@nicolasgallagher.com
 */
function html5wpautop($pee, $br = 1) {
    if ( trim($pee) === '' )
            return '';

    $pee = $pee . "\n"; // just to make things a little easier, pad the end
    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    // Space things out a little
    // *insertion* of section|article|aside|header|footer|hgroup|figure|details|figcaption|summary
    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr|fieldset|legend|section|article|aside|header|footer|hgroup|figure|details|figcaption|summary)';
    $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
    $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
    $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
    if ( strpos($pee, '<object') !== false ) {
            $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed
            $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    }
    $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
    // make paragraphs, including one at the end
    $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
    $pee = '';
    foreach ( $pees as $tinkle )
            $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
    $pee = preg_replace('|<p>\s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
    // *insertion* of section|article|aside
    $pee = preg_replace('!<p>([^<]+)</(div|address|form|section|article|aside)>!', "<p>$1</p></$2>", $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
    $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
    $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
    if ($br) {
            $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);'), $pee);
            $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
            $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    }
    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
    // *insertion* of img|figcaption|summary
    $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol|img|figcaption|summary)[^>]*>)!', '$1', $pee);
    if (strpos($pee, '<pre') !== false)
            $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
    $pee = preg_replace( "|\n</p>$|", '</p>', $pee );

    return $pee;
}

// remove the original wpautop function
remove_filter('the_excerpt', 'wpautop');
remove_filter('the_content', 'wpautop');

// add our new html5autop function
add_filter('the_excerpt', 'html5wpautop');
add_filter('the_content', 'html5wpautop');

프레임 워크가 아닌 html5 스타터 테마 의 svn 에서 더 많은 것을보십시오 !


3

WPtexturize 플러그인 비활성화 나를 위해 일했습니다 : WPtexturize 비활성화

그래도 꽤 straigtforward입니다 :

remove_filter('the_content', 'wptexturize');
remove_filter('the_excerpt', 'wptexturize');
remove_filter('comment_text', 'wptexturize');
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.