WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 4 years ago

#24085 closed defect (bug) (duplicate)

wpautop filter and shortcodes

Reported by: Looimaster Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.6
Component: Shortcodes Keywords: roadmap
Focuses: Cc:

Description

I've been told here that this has been fixed in WP3.6 but it wasn't. I just installed WP3.6 Beta 1 and still doing this:

[shortcode]
<img src="">
<img src="">
<img src="">
[/shortcode]

produces this:

<div class="carousel">
<p></p>
<img src="">
<img src="">
<img src="">
<p></p>
</div>

which is highly unwanted because I have to strip <p> tags manually in order to make carousel of images work.

Change History (18)

#1 @Looimaster
7 years ago

Oh, I'm sorry! The correct code:

[shortcode]
<div><img src=""></div>
<div><img src=""></div>
<div><img src=""></div>
[/shortcode]

It tries to nest div in p and Chrome converts that to <p> at the beginning and at the end.

#2 @azaozz
7 years ago

No, autop treats the string [shortcode] as text and wraps it on <p>, then the firts <p> and last </p> are removed for known shortcodes. Removing redundant line breaks from inside the shortcode, or at least the first and last one should work properly:

[shortcode]<div><img src=""></div>
<div><img src=""></div>
<div><img src=""></div>[/shortcode]

#3 @SergeyBiryukov
7 years ago

  • Component changed from General to Shortcodes

#4 @Looimaster
7 years ago

@azoazz
Yes, I think that you are right. Let's take a look at more examples:

Will work:

[shortcode]<div><img src=""></div>
<div><img src=""></div>
<div><img src=""></div>[/shortcode]

Will not work:

[shortcode]
<div><img src=""></div>
<div><img src=""></div>
<div><img src=""></div>
[/shortcode]

Will work:

[tabs][tab title="abc"][tab title="def"][/tabs]

Will not work:

[tabs]
[tab title="abc"]
[tab title="def"]
[/tabs]

Generally, from what I noticed, it tries to put <p> everywhere it can and they often appear before, after or inside <div> elements (they should appear in DIV to wrap text but if div contains nested div then it's no longer valid).

It looks like tough development task because wpautop is useful but on the other hand it prevents some shortcodes from working unless they strip additional tags.

#5 @kovshenin
7 years ago

  • Cc kovshenin added

#6 @jameskirsop
7 years ago

Just wanting to say that I've just updated to 3.6 Beta 3 and this is still an issue for me too.

The following short tags and content:

[row]
[span]
hello
[/span]
[/row]

Results in the following HTML output:

<div class="row">
<p></p>
<p></p>
<div class="span">
<p></p>
<p>hello</p>
<p></p>
</div>
<p></p>
<p></p>
</div>

#7 follow-up: @thiagof
7 years ago

Yes, the bug naturally persist.
Apparently there is a try to solve it in the wpautop and shortcode_unautop (plus others) but it is clearly not fully working.
Yep, RegExp really rocks.. but seems like it need attention - so many function around the issue and yet no result.

For now, people still need to use the hack of removing wpautop!!

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop', 12 );

#8 @markjaquith
7 years ago

  • Milestone changed from Awaiting Review to Future Release

#9 @Looimaster
7 years ago

More examples. I'm using Symple Shortcodes plugin - http://www.wpexplorer.com/symple-shortcodes/

This will not produce a paragraph inside the column:

[symple_column size="one-third" position="first"]Sample Content[/symple_column]

This will not produce a paragraph inside the column (but will produce additional <br> at the end):

[symple_column size="one-third" position="first"]
Sample Content
[/symple_column]

This will produce a paragraph inside the column (but will not work for those without unfiltered_capability if I'm not mistaken):

<div class="column_1">Sample Content</div>

The plugin does do_shortcode($content) instead of apply_filters('the_content', $content); so this may have impact on that but nonetheless I think that it's worth considering this example as well while resolving this ticket.

#10 @lkraav
6 years ago

  • Cc leho@… added

#11 follow-up: @lkraav
6 years ago

Is the original bug report example written in Visual or Text mode?

I've just discovered that it's hugely important for the wpautop() $pees array to have double line breaks to properly separate shortcodes from content. Visual editor adds double line break automatically, but in Text mode you need to do it manually.

Text mode example:

[TBS_ROW]

[TBS_SPAN size="6"]

Don't start your content earlier than here

[/TBS_SPAN]

[/TBS_ROW]

#12 in reply to: ↑ 11 @lkraav
6 years ago

Replying to lkraav:

I've just discovered that it's hugely important for the wpautop() $pees array to have double line breaks to properly separate shortcodes from content. Visual editor adds double line break automatically, but in Text mode you need to do it manually.

Either way, shortcode_unautop is still indeed borken:

This is what comes in:

[07-Oct-2013 22:08:57] Array
(
    [0] => shortcode_unautop
    [1] => <p>[TBS_ROW fluid="y"]</p>
<p>[TBS_SPAN size="6"]</p>
<p>The 6oth day.</p>
<p>[/TBS_SPAN]</p>
<p>[TBS_SPAN size="6"]</p>
<p>Your abs will be tighter, your arms will be leaner and your butt will be higher. You won’t be able to stop admiring yourself in the mirror or wipe the smile off your face.</p>
<p>[/TBS_SPAN]</p>
<p>[/TBS_ROW]</p>
)

And this is what we get:

[07-Oct-2013 22:08:57] Array
(
    [0] => shortcode_unautop return
    [1] => [TBS_ROW fluid="y"]</p>
<p>[TBS_SPAN size="6"]</p>
<p>The 6oth day.</p>
<p>[/TBS_SPAN]</p>
<p>[TBS_SPAN size="6"]</p>
<p>Your abs will be tighter, your arms will be leaner and your butt will be higher. You won’t be able to stop admiring yourself in the mirror or wipe the smile off your face.</p>
<p>[/TBS_SPAN]</p>
<p>[/TBS_ROW]
)

Big yey for unbalanced <p> tags! Is the function really supposed to remove just the first instance of <p></p>?

#13 in reply to: ↑ 7 @lkraav
6 years ago

Replying to thiagof:

Yep, RegExp really rocks.. but seems like it need attention - so many function around the issue and yet no result.

For now, people still need to use the hack of removing wpautop!!

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop', 12 );

This works. I'm not able to detect any harmful side effects on this particular site.

Is anyone here aware of an article that would explain and demonstrate step by step how the content gets processed and why this works?

I was looking at the resulting commit from discussion of #6444. That commit by @markjaquith is 5+ years old. Is the strategy still valid?

#14 @aaroncampbell
5 years ago

This seems pretty closely related to (if not a duplicate of) #14050, which has some unit tests and even patches attached (although they're out of date)

#15 @miqrogroove
5 years ago

  • Keywords roadmap added

I'm working on a roadmap proposal that would fix this with alternative shortcode syntax.

#16 @miqrogroove
5 years ago

#23280 was marked as a duplicate.

#17 @miqrogroove
5 years ago

#22272 was marked as a duplicate.

#18 @miqrogroove
4 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #6984.

Note: See TracTickets for help on using tickets.