WordPress.org

Ready to get started?Download WordPress

Forums

Does the_content() adds extra <p> & <br> to HTML comments? (8 posts)

  1. Blutarsky
    Member
    Posted 5 years ago #

    I have some HTML comments in the post.
    When rendered, the comments are enclosed into a paragraph with an additional line break like:

    <p><!--mycomment!--><br /></p>

    Is it WordPress or some plugin that does so? How to disable this beahviour?

  2. Mark / t31os
    Moderator
    Posted 5 years ago #

    Doesn't do it in HTML mode on my installs...

    If you're writing that in visual mode then the text is parsed as literal text and not code, so naturally it will be given a paragraph and linebreak.

  3. Blutarsky
    Member
    Posted 5 years ago #

    Actually the content is typed in HTML mode. There are no signs of HTML comments in visual mode....maybe a bug? Or a faulty plugin?

    Try this in HTML mode (the code in the following message)

  4. Blutarsky
    Member
    Posted 5 years ago #

    <!--pagetitle!-->
    <!--beginspoiler!-->
    <div class="jumps">In a rush?
    Jump to <a href="somelinkhere">the solution in a nutshell!</a></div>
    <!--endspoiler!-->

    Try the code above in a post

  5. Mark / t31os
    Moderator
    Posted 5 years ago #

    Yes i see the problem... and i've been toying in HTML mode a little to get an idea of the issue.

    Tested....

    Test post 1:

    <p> test</p>
    test
    <span>test</span>
    <!--test-->

    Result 1:

    <p> test</p>
    <p>test<br />
    <span>test</span><br />
    <!--test--></p>

    Test post 2:

    <div>
    <p> test</p>
    test
    <span>test</span>
    <!--test-->
    </div>

    Result 2:

    <div>
    <p> test</p>
    <p>test<br />
    <span>test</span><br />
    <!--test-->
    </p></div>

    Test post 3:

    <div>
    <p>test</p>
    <p>test</p>
    <span>test</span>
    <!--test-->
    </div>

    Result 3:

    <div>
    <p>test</p>
    <p>test</p>
    <p><span>test</span><br />
    <!--test-->
    </p></div>

    Seems to me the issue depends on what elements are present and how they are nested. I hope the above helps...

  6. Blutarsky
    Member
    Posted 5 years ago #

    Thanks for the in-depth test!
    I'll do some testing too.

    Thanks again

  7. oste15
    Member
    Posted 5 years ago #

    I have the same problem.

    When adding <span></span>

    It outputs
    <p>
    <span></span>
    </p>

  8. Michael
    Member
    Posted 4 years ago #

    As per: folkspants.com/wordpress/theming/remove-paragraph-tags-from-your-wordpress-posts-so-your-media-stays-put
    Comment out line 110 of wp-includes/default-filters.php :

    add_filter( 'the_content', 'wpautop' );

Topic Closed

This topic has been closed to new replies.

About this Topic