+44 0330 223 3428
Call Us
+44 0330 223 3428

WPTavern: WordPress Developers: Learn How to Convert Shortcodes to Gutenberg Blocks

WPTavern: WordPress Developers: Learn How to Convert Shortcodes to Gutenberg Blocks

Gutenberg contributor Gary Pendergast has published a handy sample plugin that demonstrates how to convert shortcode functionality to a Gutenberg block.

The first file shows a basic example of how to register a block with JavaScript and add block inspector controls to the sidebar. The second file is the PHP code for the plugin that converts the existing shortcode logic into a block that will work inside the new editor.

“This sample uses the ServerSideRender element,” Pendergast said. “It’s critical to remember that ServerSideRender is a stepping stone to a full block editing experience: having to call back to the server to re-render is a worse UX than native JS rendering. Use ServerSideRender to get your existing functionality ready for WordPress 5.0 now, and plan to phase it out over time.”

With WordPress 4.9.8’s “Try Gutenberg” callout just around the corner, this sample plugin may be helpful for developers who have created custom shortcode plugins for clients. If you’re not sure where to start, Pendergast’s sample plugin makes Gutenberg block creation more approachable. The Gutenberg handbook has more in-depth documentation for developers who want to improve their blocks beyond this basic example.


Gutenberg contributor Gary Pendergast has published a handy sample plugin that demonstrates how to convert shortcode functionality to a Gutenberg block. Do you have a bunch of shortcodes that you’d like to really easily turn into blocks? Here’s a sample plugin showing how to re-use your exisiting shortcode functionality in a block!https://t.co/bppHcumBlB — Gary (@GaryPendergast) July 29, 2018 The first file shows a basic example of how to register a block with JavaScript and add block inspector controls to the sidebar. The second file is the PHP code for the plugin that converts the existing shortcode logic into a block…

Source: WordPress

Related Post
WPTavern: WordPress Plugin Directory Now Features a Curated Section for Block-Enabled Plugins

WPTavern: WordPress Plugin Directory Now Features a Curated Section for Block-Enabled Plugins If you visit the plugin directory, you will notice a new section at the top featuring block-enabled plugins. WordPress 5.0 has been downloaded more than 8 million times, just one week after its release, and users are looking for blocks to extend the […]

Read more
Dev Blog: WordCamp US 2019 dates announced

Dev Blog: WordCamp US 2019 dates announced Save the date! The next WordCamp US will be held on November 1-3, 2019, in beautiful St Louis, Missouri. One of our largest events of the year, WordCamp US is a great chance to connect with WordPress enthusiasts from around the world. This is also the event that […]

Read more
WPTavern: Interview with Rachel Cherry: Automattic Pledges to Fund WPCampus’ Accessibility Audit of Gutenberg

WPTavern: Interview with Rachel Cherry: Automattic Pledges to Fund WPCampus’ Accessibility Audit of Gutenberg While at WordCamp US, I had the opportunity to catch up with WPCampus director Rachel Cherry, who is coordinating an audit on Gutenberg for the organization she leads. WPCampus launched its crowdfunding campaign at the end of November and more than […]

Read more