关闭Wordpress中的wpautop(自动将双线分隔符转换为段落)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关闭Wordpress中的wpautop(自动将双线分隔符转换为段落)相关的知识,希望对你有一定的参考价值。

  1. Open wp-includes/formatting.php, find this:
  2. function wpautop
  3. and comment its contents this way:
  4.  
  5. function wpautop($pee, $br = 1) {
  6. //Removing wpautop - the only method working is modifying core formatting.php file
  7. /*if ( trim($pee) === '' )
  8. return '';
  9. $pee = $pee . " "; // just to make things a little easier, pad the end
  10. $pee = preg_replace('|<br />s*<br />|', " ", $pee);
  11. // Space things out a little
  12. $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)';
  13. $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', " $1", $pee);
  14. $pee = preg_replace('!(</' . $allblocks . '>)!', "$1 ", $pee);
  15. $pee = str_replace(array("
  16. ", " "), " ", $pee); // cross-platform newlines
  17. if ( strpos($pee, '<object') !== false ) {
  18. $pee = preg_replace('|s*<param([^>]*)>s*|', "<param$1>", $pee); // no pee inside object/embed
  19. $pee = preg_replace('|s*</embed>s*|', '</embed>', $pee);
  20. }
  21. $pee = preg_replace("/ +/", " ", $pee); // take care of duplicates
  22. // make paragraphs, including one at the end
  23. $pees = preg_split('/ s* /', $pee, -1, PREG_SPLIT_NO_EMPTY);
  24. $pee = '';
  25. foreach ( $pees as $tinkle )
  26. $pee .= '<p>' . trim($tinkle, " ") . "</p> ";
  27. $pee = preg_replace('|<p>s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
  28. $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);
  29. $pee = preg_replace('!<p>s*(</?' . $allblocks . '[^>]*>)s*</p>!', "$1", $pee); // don't pee all over a tag
  30. $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
  31. $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
  32. $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
  33. $pee = preg_replace('!<p>s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
  34. $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)s*</p>!', "$1", $pee);
  35. if ($br) {
  36. $pee = preg_replace_callback('/<(script|style).*?</\1>/s', create_function('$matches', 'return str_replace(" ", "<WPPreserveNewline />", $matches[0]);'), $pee);
  37. $pee = preg_replace('|(?<!<br />)s* |', "<br /> ", $pee); // optionally make line breaks
  38. $pee = str_replace('<WPPreserveNewline />', " ", $pee);
  39. }
  40. $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)s*<br />!', "$1", $pee);
  41. $pee = preg_replace('!<br />(s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
  42. if (strpos($pee, '<pre') !== false)
  43. $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
  44. $pee = preg_replace( "| </p>$|", '</p>', $pee );
  45. */
  46. return $pee;
  47. }

以上是关于关闭Wordpress中的wpautop(自动将双线分隔符转换为段落)的主要内容,如果未能解决你的问题,请参考以下文章

删除自动br p wordpress

wpautop() - 当短代码属性在新行上时 -breaks args array [关闭]

如何将双数组列表转换为位图? [关闭]

在 Wordpress 中换行的正确方法 <br>

Wordpress - 点击时自动关闭移动菜单

关闭 WordPress 自动更新