Turn off wpautop (automatic converting of double line breaks into in paragraphs) in Wordpress


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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 . "\n"; // just to make things a little easier, pad the end
  10. $pee = preg_replace('|<br />\s*<br />|', "\n\n", $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 . '[^>]*>)!', "\n$1", $pee);
  14. $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
  15. $pee = str_replace(array("
  16. ", "\r"), "\n", $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("/\n\n+/", "\n\n", $pee); // take care of duplicates
  22. // make paragraphs, including one at the end
  23. $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
  24. $pee = '';
  25. foreach ( $pees as $tinkle )
  26. $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
  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("\n", "<WPPreserveNewline />", $matches[0]);'), $pee);
  37. $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
  38. $pee = str_replace('<WPPreserveNewline />', "\n", $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( "|\n</p>$|", '</p>', $pee );
  45. */
  46. return $pee;
  47. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.