Shortcodes in templates don't work anymore after WordPress 6.2.1 update

Description:

I just realized that the new WordPress version 6.2.1 removed the ability to use Shortcodes in templates:

https://core.trac.wordpress.org/ticket/58333

I’m not quite sure what the implications are since it seems like this was by design to fix a security issue. Is this something that can be addressed by you?

I use the Shortcode in the Cwicly Paragraph, not in the Shortcode Block because I need to have text before and after it.

This is how the change is described in the change log:

Block themes parsing shortcodes in user generated data; thanks to Liam Gladdy of WP Engine for reporting this issue

Confirmed on my side as well.

Shortcodes inserted into a Cwicly paragraph no longer work with WordPress 6.2.1 inside templates. This also affects shortcodes inserted into the Dynamic inserter . These however, are not affected when used directly on a page or post).

Standard shortcode blocks are still working.

Either roll back to WordPress 6.2.0 or use a Cwicly code block to overcome this:

<p>Text before <?php echo esc_html(do_shortcode('[shortcode-name]')) ?> text after<p>

/* Other usages
<?php
echo do_shortcode('[shortcode-name']);
echo do_shortcode('[shortcode-name attr=' . get_field('acf_field') . ']');
echo do_shortcode('[shortcode-name] ' . get_field('acf_field') . ' [/shortcode-name]');
?>
*/

Edit: added information about shortcodes used directly on pages and that the dynamic inserter is affected.

1 Like

That’s kinda crazy. I feel like this level of change will have to get reversed in 6.2.2. I’d suggest rolling back and waiting a few days to see what happens.

1 Like

Well thats the problem. It seems to me that they did this for security reasons so this functionality will not return.

This is terrible, so many sites broken…
I guess they’ll have to patch this very fast :wink:

Regarding WP shortcodes in a more general way, I always use the PHP do_shortcode() method mentionned above because it prevents from rendering the infamous empty <p></p>.

1 Like

Thanks for this @nadim!

I never tried it this way since I never touched php before^^
Will take a look at it this time.

Hi @nadim,

could you give me a bit more information on how to do this with the Cwicly code block? I don’t know how to do that.

could you give me a bit more information on how to do this with the Cwicly code block? I don’t know how to do that.

Sure, @Jonas . Let me PM you and I will help you out.

1 Like

Hello everyone,

Sorry to hear some of you are experiencing trouble with this. It was an unfortunate decision to push it through without any warning whatsoever.

We’re aware of the situation and will be investigating it further.

Cheers,

WordPress 6.2.2 fixed it.

2 Likes

Here is the official statement

1 Like

Thank you for the link, @StrangeTech.

Moving this thread to General as it seems to have been addressed by the WordPress team.
Thanks for the workarounds posted here!

Cheers,

We just added this very quick tip for anyone using shortcodes in templates: