ShortCode and extra </p>

[box id='1' text="some texte"]

the shortcode, at one point is outputting text

the html result is : /p some text /p

There is an extra closing paragraph in the start and and opening at the end... WHY ?

where those come from ?.... any idea ?.. it screw my w3 validation !

** note i have found that... but look all "patched" to me...any clean solution... wp is dirty ? reference

Topic shortcode html Wordpress

Category Web


When using a shortcode in the block editor, I had a really hard time removing extra p tags until I used the "Custom HTML" block and inserted the shortcode in there.

Hope this helps someone out there like me.


I had the same problem and checked the $content in the add_filter() function. There you can see what happen with the shortcodes. I ended up with an easy plugin, that removes silly p and br tags on shortcodes: http://www.johannheyne.de/wordpress/shortcode-empty-paragraph-fix/


I discover that it's a know bug, and will be fix in future release Reference here So then, i used this code... not pretty, but do the magic !, thanks

$content = do_shortcode( shortcode_unautop( $content ) );
if ( '</p>' == substr( $content, 0, 4 )
and '<p>' == substr( $content, strlen( $content ) - 3 ) )
    $content = substr( $content, 4, strlen( $content ) - 7 );
return '<div my stuff>' . $content . '</div>';

Make sure there is a double line-break before and after the shortcode in the editor;

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sodales, neque vitae imperdiet aliquet, elit tortor egestas dui, vel fermentum neque est eu est.

[box id='1' text="some texte"]

Lorem ipsum dolor sit amet...

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.