7/11/2013

WordPress: How to Stop Extra Paragraph Tags from being inserted in your HTML / added by the text editor

Ugh, I'm still learning about WordPress and its idiosyncrasies.

I've known for some time that the HTML is rendered in an odd way: Paragraph tags are hidden in the text editor by default.

So, I used a plug-in to show the <p> tags in the text editor. After that, I started to get other odd problems when pasting HTML into the text editor. After I would save or update the document in WordPress, there would be all these weird, gaping spaces.

Looking at the HTML, I could see things like this:
<p><div>Hey, I don't want paragraph tags around the divs.  </div></p> 
<p><!-- Why are there paragraphs around my comments? --></p>
It was really annoying, but not unexpected.

Well, I fiddled with WordPress a bit and came away with this solution....

How to Stop WordPress from using the function wpautop

  • You have to use a text editor, and probably FTP.
  • Find the folder: /wp-includes/
  • Find the file: formatting.php
  • Open that file in your text editor.
  • Search for the words "function wpautop"
  • Add these yellow lines inside the function. (And, yes, it says "pee" for some reason.)
function wpautop($pee, $br = true) { 
// DISABLE wpautop BY RETURNING THE DATA SENT 
return $pee;
... [leave everything else] ...
}
  • Save the altered text.
  • Upload it back to the /wp-includes/ folder.
Now, it should skip over the auto-paragraph inserts.
Probably not the greatest fix, but its working for my purposes.

Hope that helps you, too.

(Now, if I could only fix Blogger's dumb editor in the same way.)

Note

You may want to add this plug-in for more paragraph control.
Also, I do not know if you'll need to do this again when you upgrade your WordPress installation.

No comments :

Post a Comment