WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 7 months ago

#40021 closed defect (bug) (maybelater)

Empty p tags when adding multiple consecutive shortcodes in the editor.

Reported by: kmgalanakis Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.2
Component: Editor Keywords:
Focuses: ui Cc:
PR Number:

Description

Steps to reproduce

  • Create a simple shortcode in your functions.php file.
    <?php
    function dummy_div_handler( $atts ){
        return "<div>Lorem ipsum dolor sit amet.</div>";
    }
    add_shortcode( 'dummy-div', 'dummy_div_handler' );
    
  • Add the [dummy-div][dummy-div] shortcodes to a new page using either the Visual or the Text editor.

The markup that is outputted on the browser is

<p><div>Lorem ipsum dolor sit amet.</div><div>Lorem ipsum dolor sit amet.</div></p>

which clearly is invalid. The browser processes the page source and transforms those <p> and </p> tags to empty <p> tags by adding the missing opening or closing tag, so the resulting markup is something like

<p></p><div>Lorem ipsum dolor sit amet.</div><div>Lorem ipsum dolor sit amet.</div><p></p>

Change History (2)

#1 @kmgalanakis
3 years ago

  • Focuses ui added

#2 @noisysocks
7 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

It looks like shortcode_unautop() is supposed to remove those <p> tags, but it only supports removing a single shortcode. To fix this, we could modify shortcode_unautop() to remove multiple shortcodes. Such a patch would have to include lots of unit tests because the combination of shortcodes and autop is very scary.

This is not a priority as the block editor makes both shortcodes and autop largely obsolete, but I'd be happy to see this ticket re-opened if someone wants to submit a patch.

Note: See TracTickets for help on using tickets.