ShortCode and extra </p>

[box id=’1′ text=”some texte”]

the shortcode, at one point is outputting text

Read More

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

Related posts

Leave a Reply

4 comments

  1. 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>';
    
  2. 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…

  3. 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.