Shortcode Block not working in Synched Pattern in Template
Description
The Shortcode Block does not parse shortcodes when used in Synched Patterns in Block Editor Page Templates.
Step-by-step reproduction instructions
- Go to a blank page and insert the Shortcode Block into the content. I used this shortcode for testing:
[caption]Caption[/caption] - Duplicate the block and transform it to a Synched Pattern.
- Go to the frontend and observe both blocks working from inside the page content.
- Now cut both blocks to the clipboard and navigate to the page template. Insert the blocks somewhere.
- 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
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
I can confirm that the issue is there, sharing a screencast: https://github.com/user-attachments/assets/b7b31ae6-0819-46e2-88c2-802775147d52
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 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.
Thanks for linking the two together. Agreed that the issue should be kept open, and hopefully a solution is possible.
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
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.)