gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Shortcode Block not working in Synched Pattern in Template

Open krokodok opened this issue 1 year ago • 6 comments

Description

The Shortcode Block does not parse shortcodes when used in Synched Patterns in Block Editor Page Templates.

Step-by-step reproduction instructions

  1. Go to a blank page and insert the Shortcode Block into the content. I used this shortcode for testing: [caption]Caption[/caption]
  2. Duplicate the block and transform it to a Synched Pattern.
  3. Go to the frontend and observe both blocks working from inside the page content.
  4. Now cut both blocks to the clipboard and navigate to the page template. Insert the blocks somewhere.
  5. Go to the frontend and observe only the block working, that it is not a Synched Pattern. The other displays the raw shortcode content without rendering.

Screenshots, screen recording, code snippet

Image Image

Environment info

I used WordPress Playground with theme Twenty Twenty-Five, WordPress version 6.7.1 and Php 8.0.

Please confirm that you have searched existing issues in the repo.

  • [x] Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • [x] Yes

Please confirm which theme type you used for testing.

  • [x] Block
  • [ ] Classic
  • [ ] Hybrid (e.g. classic with theme.json)
  • [ ] Not sure

krokodok avatar Dec 20 '24 22:12 krokodok

I can confirm that the issue is there, sharing a screencast: https://github.com/user-attachments/assets/b7b31ae6-0819-46e2-88c2-802775147d52

Rishit30G avatar Dec 21 '24 10:12 Rishit30G

You can add the shortcode to a template part instead of a synced pattern to work around this.

I think shortcode processing was never added to synced patterns (or before that reusable blocks) as they were more commonly added to posts, and the code that renders a post already performs shortcode processing on behalf of all the blocks within the post.

talldan avatar Dec 23 '24 01:12 talldan

@talldan Thank you for the explanation. I understand the workaround. Still, I would prefer for this to be fixed. Less tech-savy users can easily be frustrated by this. And more important: It might very well be that template parts and synched patterns will be unified in the future (https://github.com/WordPress/gutenberg/issues/57011), and the Shortcode Block should continue to work then. I'll link this bug to this issue as well.

krokodok avatar Dec 23 '24 10:12 krokodok

Thanks for linking the two together. Agreed that the issue should be kept open, and hopefully a solution is possible.

talldan avatar Dec 24 '24 05:12 talldan

this work for me:

function render_shortcodes_in_blocks( $block_content ) {

return do_shortcode( $block_content );

} add_filter( 'render_block', 'render_shortcodes_in_blocks', 10, 2 );

added in functions.php

joseluis6425 avatar Sep 07 '25 12:09 joseluis6425

This is completely ridiculous Gutenberg behavior. I just lost an hour over this. Thanks @joseluis6425 for the workaround. I'll just migrate my shortcodes to blocks now.

It's beyond frustrating how short-sighted the Gutenberg development is. It's like trying to tear everything down that WordPress was built on; shortcodes are an integral part of many WP themes and plugins and the lack of support inside synched patterns is just stupid as far as I'm concerned. (Apologies for the language; you have no idea how frustrated I am right now.)

nextab avatar Dec 30 '25 19:12 nextab