+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: Codecademy Launches New Free PHP Course

WPTavern: Codecademy Launches New Free PHP Course Codecademy introduced a new free course today called Learn PHP. The company, which offers free coding courses, is rebuilding its PHP education after removing all of its PHP courses in 2017. A Codecademy representative explained that the courses were outdated and that their team thought PHP was declining […]

Read more
WPTavern: Gutenberg Cloud Team Advocates for Making WordPress.org’s New Block Directory a CMS-Agnostic Library

WPTavern: Gutenberg Cloud Team Advocates for Making WordPress.org’s New Block Directory a CMS-Agnostic Library Frontkom‘s presentation at WordCamp Nordic introduced the audience to the Gutenberg Cloud project, which allows developers to share JS-only blocks across CMS platforms. Marco Fernandes and Thor Andre Gretland, representatives of the 45-person agency based in Europe, are also part of […]

Read more
WPTavern: WPWeekly Episode 349 – Sandy Edwards and the Kids Event Working Group Initiative

WPTavern: WPWeekly Episode 349 – Sandy Edwards and the Kids Event Working Group Initiative In this episode, John James Jacoby and I are joined by Sandy Edwards. Sandy gave us a behind the scenes look at what it takes to organize a WordPress event for children and teens. She also provides background information on a […]

Read more