0

On my page I've inserted some simple HTML via the text editor:

<div class="box box-tv">
<img class="logo-ma" src="http://kabultec.org/dev/wp-content/uploads/2017/07/logo-nbc.svg"/>
<img class="logo-ma" src="http://kabultec.org/dev/wp-content/uploads/2017/07/logo-nbc.svg"/>
<div class="logo-ma"></div>
<div class="logo-ma"></div>
</div>

But when I view the front-end source code, an extra </p> appears after the second <img> (screenshot). How can I determine the cause of this </p>?

  • I have searched my source code for a potential opening <p> tag that I forgot to close, but none exists.

  • I have also tried disabling auto-insertion of <br> and <p> tags, by adding code to functions.php.

    add_action('spacious_before_body_content', 'nobrp'); function nobrp() { if (is_page('232')) { remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); function wpse_wpautop_nobr( $content ) { return wpautop( $content, false ); } add_filter( 'the_content', 'wpse_wpautop_nobr' ); add_filter( 'the_excerpt', 'wpse_wpautop_nobr' ); } }

  • I also added code to remove <p> tags around <img> tags (see here). But that did not resolve my issue either.

The motivation for removing the </p> is that I plan to add more images to this page, inside a flex container, so they are laid out a specific way on the page. The extra </p> is causing elements to not align as expected.

Workarounds are appreciated, but if possible, I am most interested in determining the cause of this issue.

Thanks.

1 Answer 1

0

I've used these in a template to remove all p tags from an editor:

remove_filter('acf_the_content', 'wpautop');

// This is where the content of the editor was written out by the template

add_filter('acf_the_content', 'wpautop'); //add back the filter 
//so it doesn't mess with other stuff

Also you could try deleting the line break between the images. It will look ugly in the editor but may solve the issue.

Edit: I just realized this is for acf field, but the ACF plugin could also solve your problem this way...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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