Simple WordPress plugin with a group of custom reusable Gutenberg blocks to use on any project. Written with PHP, Javascript and JSX support – build step required.
- Upload the plugin files to the
/wp-content/plugins/gutenberg-blocks
directory. - Activate the plugin through the 'Plugins' screen in WordPress
- Build assets: Go to the plugin folder from terminal, and run these commands (
v19.6.0
of Node is recommended):npm install gulp npm run build
- Enjoy!
You are welcome to contribute with this project. You can create a fork from this repository and send PRs or open issues here.
We build our dynamic blocks as a React component that isn't aware of Gutenberg. That block accepts a prop that is used to pass block attributes. But for now, Gutenberg only allow to render the dynamic blocks using PHP. So, to be able to reuse the same React Component that we have in the Edit function we based on this article from WooCommerce.
And what we do basically is:
- When the post or page is saved, only an empty
div
element with an ID or class is saved to the Database. - In the PHP
render_callback
, we append the block attributes asdata-
HTML attributes to thatdiv
. So this is what ends up being rendered in the page. - We enqueue a new
frontend.js
file which will import the React component. - From there, we just need to render the React component as you would render any other React app:
render(BlockComponent, divElement)
. We readdata-
HTML attributes and pass them as props to the component.
WordPress is free software, and is released under the terms of the GNU General Public License version 2 or (at your option) any later version.
- 0.1.0
- Release