Shortcode: Add the ability to preview the inserted shortcode#70532
Shortcode: Add the ability to preview the inserted shortcode#70532shubhtoy wants to merge 3 commits into
Conversation
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @shubhtoy! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
794f9ea to
0c9e4f5
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
Hi @shubhtoy, Great work 🚀, I have tested the PR, everything looks good and working: Screen.Recording.2025-06-27.at.8.11.03.PM.movJust one thing, when there is no input in shortcode, it renders: Reference:Screen.Recording.2025-06-27.at.8.13.00.PM.mov |
|
Thanks @Infinite-Null for testing the PR, I'll look into this issue and push a patch soon. |

What?
Closes #70519
Adds preview functionality to the core/shortcode block following the same pattern as the custom HTML block.
Why?
Previously, the shortcode block only showed a text input field in the editor without any visual preview of how the shortcode would render. This made it difficult for users to see what their shortcode output would look like without switching to the frontend or preview mode. The custom HTML block already had this preview functionality, and it makes sense to provide the same user experience for shortcodes.
How?
The implementation follows the same pattern as the custom HTML block:
Editor Changes (
edit.js):useStateandisPreviewServerSideRendercomponent to render shortcode previewVisuallyHiddendescriptionServer-side Changes (
index.php):render_block_core_shortcode()to detect when called fromServerSideRender(editor preview)textattribute is present (fromServerSideRender), usesdo_shortcode()to process the shortcodewpautop()on block contentTesting Instructions
[gallery]or any custom shortcode)Screenshots or screencast
Before
Screen.Recording.2025-06-26.at.5.28.41.PM.mov
After
Screen.Recording.2025-06-26.at.5.29.38.PM.mov