0

I am trying to post static pages with HTML content. So I need to disable wpautop, but when I do this my content is stripped of all <p> tags it has.

I remove the wpautop filter from my header.php file.

if( is_page() ) {
    remove_filter( 'the_content', 'wpautop' );

Without this the HTML code for images, and other graphical aspects of my site are broken.

With it WordPress seems to be formatting my content to have absolutely no <p> tags.

How do I disable the automatic insertion of these tags while also keeping my content's tags?

0

Why are manually placed paragraph tags being removed?

I can't say for sure. I found one support thread which suggested it was being removed by the editor. My own testing deems this to be untrue.

My local development server also doesn't appear to have any of these problems, except for the insertion of paragraph tags. After removing the wpautop filter on that local server, there are no formatting issues to be spoken off. So for some servers simply removing the filter may suffice. So again, I can't be sure why.

How to disable the auto insertion of <p> tags, and prevent manually placed paragraph tags from being removed?

As mentioned in the question to disable the auto insertion of p tags, you can add this php code to your theme. Or you can make a plugin. Where you want to disable the insertion matters for where you place the code.

It is a simple matter of this though:

remove_filter( 'the_content', 'wpautop' ); 

To prevent the removal of tags in html code content, you can wrap the paragraph body with <div> and </div>.

An example:

    <div><p>My super duper long paragraph</p></div>
    <div><p>My small paragraph which happens to be even longer.</p></div>

This thread where I found the answer, suggests that you can wrap two paragraphs in one div tag; my testing, however, proved this an ineffective solution.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.