Shortcodes on User Guide page

First, the shortcodes are visible in the page preview, so they are in the meta tag?

Second, the shortcode is outputting invalid HTML for the list in the search results. The </p> should not be after the <ul>, and the <p> should not be before the </ul>.

This is not the shortcode, this is WordPress/ClassicPress messing with me.
I am not sure if it happens by default or if it is wp_kses that does this garbage but of course I did not code a ShortCode to produce a List that separates lists with paragraphs.

Unfortunately, nothing I can do about it right now.

Why the shortcode is visible, I already explained in the other ticket, and it will stay like that until we have a summary for that page, and/or I have server access, to actually develop a full fledged custom SEO system that does not take the excerpt, or passes it thru do_shortcode at least. But I think we sill just solve this by adding the page summary.

I will keep this thing here open for the P tag issue, I hope I can find some sort of solution to this, but I fear not, at least, not fast. It is after all a very, very annoying core issue, which as said, I believe is due to wp_kses (which I use to clean the output).
Will see what I can do, added this to Reminders for new cp doc

Debugging this shows that is clearly that this is a problem happening when HTML is inside [][/] shortcodes (enclosing), and only when certain HTML like a li/li is passed.

The $content passed to the ShortCode (before even processing it) already has that rather weird paragraphing without any process at all

Thus this is a likely a core problem, something tries to be smart and add p’s where really there shouldn’t be any interference at all.
It also 100% contradicts this https://developer.wordpress.org/apis/handbook/shortcode/#output, which states the output will not have these things applied.

I am not sure what we can do about this, surely there must be some way to stop this unwanted behaviour.
Open to inputs - I already tried removing wpautop

Will see.

Are you saying that the content HTML does not contain the <ul> and </ul> tags?
Can you remove the list or make the shortcode take a parameter for the ID to use instead of enclosing it?

No, I am saying and doing this:

Debugging this shows that is clearly that this is a problem happening when HTML is inside [][/] shortcodes (enclosing), and only when certain HTML like a li/li is passed.

The $content passed to the ShortCode (before even processing it) already has that rather weird paragraphing without any process at all

This is a widely known problem, as google tells.
And I am opening a ticket now in WP Support to get to the ground of it.

1 Like

Nevermind, brainstorming in the Slack channel helped me and I have a solution for this, which will resolve this problem
For the records, wpautop does this before the shortcode is run
Thus the shortcode receives a $content that already has been messed with.
To avoid that, remove wpautop globally, and add it again after shortcodes are run.

Something like this:

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

This preserves the wpautop “magic” on posts but avoids it messing with shortcodes.

1 Like

The issue with P is resolved, the issue with ShortCodes visible will be resolved as soon summary is written.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.