31 Tips for Gutenberg Development by Zac Gordon
This is a curated post with all the 31 awesome tips for #Gutenberg by Zac Gordon.
wp.element is the WordPress abstraction layer on top of React and ReactDOM
wp.i18n is the client side library for localization in WordPress, make it a dependency in your block JS files as ‘wp-i18n’ — https://buff.ly/2zQBQ1v
You can use default WordPress Dashicons as Block Icons. You can also use custom SVG Icons :) Here is a tutorial how => https://buff.ly/2BSlA1s
/blocks/library is where all of the default Gutenberg Blocks live. Check out how they are built — https://buff.ly/2BSAVPz
Use the ‘keyword’ setting to have your Block show up for keywords not found in the name of the block. Here is a tutorial showing how => https://buff.ly/2BdM4gP
In case you haven’t explored it yet, the Gutenberg Developer Handbook is pretty helpful — https://buff.ly/2BBK1Dz
Did you know there is a “Gutenberg Theme” in development you can checkout? twentyeighteen?
To use JSX in your blocks, simply add the ‘transform-react-jsx’ plugin like done in the Gutenberg Core .babelrc file — https://buff.ly/2CY76Og
There is an interesting discussion on how plugins should handle fallback to the Classic Editor. If you’re a plugin dev, you should check it out — https://buff.ly/2D4xUwh
There are 5 categories of blocks you can choose from when creating a custom blocks: common, formatting, layout, widgets & embed https://buff.ly/2p9AY7t
Ever use the Gutenberg Demo when you install the plugin? Checkout the simple JS file that loads the block content. See GB comment attributes in work. https://buff.ly/2BQ88eZ
If you find yourself starting to or wanting to rebuild Core blocks… It’s possibly time to switch to a template or reusable blocks approach.
registerBlockType() is at the heart of building custom blocks.
Here’s how it works https://buff.ly/2lkIAic
In general, custom blocks belong in plugins, not themes. Themes can style and integrate to an extent with blocks though! IMHO
Use this helpful online tool to convert any SVG into valid JSX that can be copied and pasted as the icon for your custom block https://buff.ly/2pVPD6F
Yes. You do actually need to know some React to work with Gutenberg. Or at least you will learn some React in learning Gutenberg ;) #thisisagoodthing
Want to customize the color palette for blocks and make them match the color scheme for your theme? It’s just a few lines of PHP :) Here’s how — https://buff.ly/2Cq6Pnj
The component in Gutenberg is an easy way to add accessibility and slickness to your custom block controls. 👍 📖 Learn how to use it in your blocks — https://buff.ly/2CALuYu
Block Templates let you assign default blocks to posts, pages or custom post types. You can even lock them down. 📖 Here’s how they work https://buff.ly/2F3G8Ga
As it will roll out at first, Gutenberg is not a replacement for rich front end site or page builder plugins. It is a greatly enhanced editing experience, but not a replacement.. yet.
You will likely use wp.i18n.__() all over the place in your block code to make your block UI text available for translation. 👍 📖 It’s simple, here’s how! https://buff.ly/2CJ6Vpr
Using JSX to create your block UIs can save you time and provide cleaner, more readable code. 👍 📖 Read this Official Guide to Get Up and Running https://buff.ly/2CNSssr
Gutenberg has a few addthemesupport() options for Theme Developers.🎨 📖 Check out the reference for these in the Gutenberg Handbook here — https://buff.ly/2miv1Ay
For API requests w/out React inside Gutenberg, try wp.apiRequest() — https://buff.ly/2Dq0fhc
OR, if you’re using React, try withAPIData() in your component 👍 — https://buff.ly/2DqSAPQ
The optional “description” setting for registerBlockType will let you set a translatable description for your block. https://buff.ly/2DGAjhp
Whoot whoot! Documentation for Block Templates is up on the GB Handbook! Theme devs ~ you’re gonna love these :) https://buff.ly/2mDDtdN
If you want to interact with meta boxes, plugin options or other database data, a good convention is custom API end points and JS api calls from your blocks. 👍
If you like these tips, make sure to checkout his Gutenberg Course.
Originally published at Gutenberg Hub.