• Hi there – I am a relative newcomer to WordPress (but not to HTML & CSS) and this is my first post.
    I am one of a number of editors on WordPress for my local organisation and I’m getting HTML syntax/nesting errors since the update to WordPress 4.7

    To better understand what is happening I narrowed it down to the following HTML code blocks which illustrate the problem.
    If you paste the code into the EditPage text editor and publish you should find unwanted </p> tags and other problems on the “View Page Source” webpage.

    I am interested to see if others can confirm this as a problem.

    
    <span>
    <img src="image.png" alt="thumb">
    <p>Text</p>
    </span>
    
    <div>
    <img src="image.png" alt="thumb"><br>
    <p>The br tag vanishes</p>
    </div>
    
    <div><img src="image.png" alt="thumb"><div>Caption</div></div>
    
    <li>
    <img src="image.png" alt="thumb"><p>Text</p>
    </li>
    
    <li>
    <img src="image.png" alt="thumb"><b>Almost the same as the previous code block but with no error</b>
    </li>
    
    <div><img src="image.png" alt="thumb">No error here either</div>
    
    <div><a href="document.htm"><img src="image.png" alt="thumb"></a><p>Text</p></div>
    
    <a href="document.htm"><img src="image.png" alt="thumb"><p>Text</p></a>
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • https://wordpress.stackexchange.com/questions/13798/remove-empty-paragraphs-from-the-content

    WordPress will automatically insert <p> and </p> tags which separate content breaks within a post or page. If, for some reason, you want or need to remove these, you can use either of the following code snippets.

    To completely disable the wpautop filter, you can use:

    remove_filter(‘the_content’, ‘wpautop’);
    If you still want this to function try adding a later priority value to your filter something like:

    add_filter(‘the_content’, ‘removeEmptyParagraphs’,99999);

    Thread Starter jim5471

    (@jim5471)

    I am aware of WordPress automatically inserting <p> and </p> tags.

    But this is different – If you try the code you should only see the p closing tag ie: </p>
    there is no p opening tag.

    “Disabling the wpautop filter” looks interesting. Do I just paste it in with the HTML ?

    I am also getting extra P closing tags after certain IMG elements since updating to 4.7. The browser then automatically creates a matching opening tag, so an extra P is inserted where it should not be.

    The add_filter and remove_filter functions must be in the php template, or possibly the theme’s functions file. Removing the wpautop filter can be useful, but can also have negative consequences if you rely on it to insert paragraph tags in the rest of the content.

    Thread Starter jim5471

    (@jim5471)

    Hi danteand
    Thanks for taking the trouble to check my post and confirm you also are seeing the problem.

    I spent a bit of time last night and also saw it on a couple of “Best of WordPress” websites but there aren’t many examples.
    Guess my new job is safe for the moment – at least I can explain to my boss why there are coding errors on my pages.

    The wpautop info is useful to know but I cannot go there as I only have an Editor account.

    The website code that results from my OP is here. I have added blank lines to split the code blocks up to make it easier to read.

    <p><span><br />
    <img src="image.png" alt="thumb"></p>
    <p>Text</p>
    <p></span></p>
    
    <div>
    <img src="image.png" alt="thumb"></p>
    <p>The br tag vanishes</p>
    </div>
    
    <div><img src="image.png" alt="thumb"></p>
    <div>Caption</div>
    </div>
    
    <li>
    <img src="image.png" alt="thumb"></p>
    <p>Text</p>
    </li>
    
    <li>
    <img src="image.png" alt="thumb"><b>Almost the same as the previous code block but with no error</b>
    </li>
    
    <div><img src="image.png" alt="thumb">No error here either</div>
    
    <div><a href="document.htm"><img src="image.png" alt="thumb"></a></p>
    <p>Text</p>
    </div>
    
    <p><a href="document.htm"><img src="image.png" alt="thumb"></p>
    <p>Text</p>
    <p></a></p>
    Thread Starter jim5471

    (@jim5471)

    I did some more research and found some recent bug tickets for a couple of other examples of this problem which hopefully will inform others searching for this bug.

    https://core.trac.www.ads-software.com/ticket/39307 << </p> tag inserted in <figure>
    https://core.trac.www.ads-software.com/ticket/37672 << wpautop adds a closing p-tag without an opening p-tag
    https://core.trac.www.ads-software.com/ticket/38656 << wpautop incorrectly handling paragraphs within block elements
    https://core.trac.www.ads-software.com/ticket/39377 << wpautop adds a extra </p>

    Unfortunately the developers only seem to be preparing patches to fix <figure> & <span> tags and are unaware that there is a wider problem.
    Maybe WordPress Support will tell them.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WordPress 4.7 is inserting tags into my HTML’ is closed to new replies.