wordpress 空行處理

讓wordpress能夠使用兩個以上空行
並拿掉p段落


wp-includes\formatting.php
找到function wpautop( $pee, $br = true )

拿掉

// Add a single line break above block-level opening tags.
$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);

// Add a double line break below block-level closing tags.
$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);

拿掉

// Remove more than two contiguous line breaks.
$pee = preg_replace("/\n\n+/", "\n\n", $pee);

// Split up the contents into an array of strings, separated by double line breaks.
$pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);

// Reset $pee prior to rebuilding.
$pee = '';

// Rebuild the content as a string, wrapping every bit with a <p>.
foreach ( $pees as $tinkle ) {
    $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
}
// Under certain strange conditions it could create a P of entirely whitespace.
$pee = preg_replace('|<p>\s*</p>|', '', $pee);

// Add a closing <p> inside <div>, <address>, or <form> tag if missing.
$pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);

// If an opening or closing block element tag is wrapped in a <p>, unwrap it.
$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);

// In some cases <li> may get wrapped in <p>, fix them.
$pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee);

// If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
$pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
$pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);

// If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);

// If an opening or closing block element tag is followed by a closing <p> tag, remove it.
$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);

拿掉

// Replace any new line characters that aren't preceded by a <br /> with a <br />.
//$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);

拿掉

// If a <br /> tag is before a subset of opening or closing block tags, remove it.
//$pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);

底下加入

// Remove unwant BRs.
$pee = preg_replace('!(\s*</?(?:li|ul|ol)[^>]*>)\n<br />!', '$1', $pee);

結果測試:
不空行
空1行

空2行

空3行

結束

code測試

code
code

標題測試

內文

  • 標題測試
    內文

= 標題測試(內文前空行) =

內文

  • 標題測試(內文前空行)

內文

--
現在還在寫blog分享資訊的人越來越少,如果覺得文章對您有幫助,歡迎在底下留言,這樣我也比較有動力繼續寫下去,謝啦!

Leave a Comment

Your email address will not be published. Required fields are marked *

 

Scroll to Top