Wrap stray text in <p> tags

WordPress issue.. how do I wrap stray text in P tags?

Example:

Read More

Before-

<div class = "content">
    <img src = "hello.jpg"/>
    <h1>Introduction</h1>
    Hello! this is stray text that I want to wrap with p tags
    Hello! This is another set of stray text
</div>

After-

<div class = "content">
    <img src = "hello.jpg"/>
    <h1>Introduction</h1>
    <p>Hello! this is stray text that I want to wrap with p tags</p>
    <p>Hello! This is another set of stray text</p>
</div>

Related posts

Leave a Reply

2 comments

  1. WordPress uses a plugin called wpautop. This script automatically adds <p> </p> tags to new lines. In most cases, this is helpful. Sometimes, it can be a pain. In such a case you can use the Disable Autop Plugin.

    You can manually control this by changing the core WordPress scripts. I suggest using a plugin.

  2. Where is the stray text coming from? Is it being entered into the WordPress WYSIWYG editor? If so, it’ll automatically wrap the text in P tags if you have empty lines before and after the text.