"Frank's skill in asking the right questions is un-mistakable, and is at the core of his leadership philosophy.

The power of these questions cannot be underestimated, especially if you want to lead and not manage."
—John Cave
Westhaven Worldwide Logistics

If not otherwise stated—all postings © Frank D. Kanu. All rights reserved.


WordPress wpautop

The wpautop function (file formatting.php) is rather buggy: not all <p> have a </p> and vice versa. Duplicated <br /> get replaced with a single one.

The first is bad for obvious reasons, the second tampers with my formatting. I changed

Below is the changed function the way I use it:
No <p> and </p> but <br /> instead and leaving multiple line breaks (even when empty) intact.

You might also want to check
wpautop - bug
Missing close </p> tag in wpautop
Disable wpautop Plugin

function wpautop($pee, $br = 1) {
  $pee = $pee . "n"; // just to make things a little easier, pad the end
  $pee = preg_replace('|<br />s*<br />|', "nn", $pee);
  // Space things out a little
  $allblocks = '(?:caption|colgroup|div|dl|dd|dt|ul|ol|pre|select|form|address|math|style|script|object|input|param)';

  $pee = preg_replace('!(</' . $allblocks . '>)!', "$1n", preg_replace('!(<' . $allblocks . '[^>]*>)!', "n$1", $pee));

  $pee = str_replace('[<br />]*<br /><br /></blockquote>', '<br /><br /></blockquote>',
         str_replace('</blockquote>', '<br /><br /></blockquote>', str_replace('<br>', '<br />', $pee)));

  $pee = str_replace(array("rn", "r"), "n", $pee); // cross-platform newlines
  if ($br) {
    $pee = preg_replace('/<(script|style).*?</\1>/se', 'str_replace("n", "<WPPreserveNewline />", "\0")', $pee);
    $pee = preg_replace('|(?<!<br />)n|', "<br />n", $pee); // optionally make line breaks
    $pee = str_replace('<WPPreserveNewline />', "n", $pee);
  if ( strstr( $pee, '<pre' ) )
    $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') .  stripslashes(clean_pre('$2'))  . '</pre>' ", $pee);

  return $pee;


This blog-entry is protected by a digital fingerprint:785273ed81985582c8a1be62f78c9459

Two other Opinions:

  1. Bettyue
    09:09 on Monday, April 7th, 2008
    well done, man
  2. Katya
    09:25 on Thursday, July 16th, 2009

Because I value your thoughtful opinions, I encourage you to add them.

Please leave your Response right here:

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please do not be offended if I edit your response for clarity or to keep out questionable matters, however, and I may even delete off-topic responses.

« 04/22/2007     Got apples? »

Navigation, Archives and Links

This blog is designed to provide accurate and authoritative information in regard to the subject matter covered. If legal advice or other expert assistance is required, the services of a competent professional should be sought.