{"id":1329,"date":"2017-07-27T11:58:54","date_gmt":"2017-07-27T06:58:54","guid":{"rendered":"https:\/\/thedevcouple.com\/?p=1329"},"modified":"2017-12-07T13:37:18","modified_gmt":"2017-12-07T08:37:18","slug":"build-custom-block-gutenberg-wordpress-editor","status":"publish","type":"post","link":"https:\/\/thedevcouple.com\/build-custom-block-gutenberg-wordpress-editor\/","title":{"rendered":"How to Build a Custom Block for Gutenberg WordPress Editor?"},"content":{"rendered":"<p>Gutenberg is all that you hear about nowadays. Plugin developers want to understand how to build custom blocks for the new Gutenberg editor in WordPress.<\/p>\n<p>For that purpose, I wrote a boilerplate which is heavily documented and will help you kick-start with developing custom blocks, built in ReactJS, ESNext, with Webpack, etc.<\/p>\n<p>I also wrote an introductory article \u2192\u00a0<a href=\"https:\/\/ahmadawais.com\/gutenberg-boilerplate\/\" target=\"_blank\" rel=\"noopener\">Introducing Gutenberg Boilerplate For Third Party Custom Blocks<\/a>!<\/p>\n<blockquote><p>\ud83d\ude80 <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/\" rel=\"nofollow noopener\" target=\"_blank\">GITHUB: \u2605 773 \u2442 88 \u2192<\/a><\/p><\/blockquote>\n<p><strong>PRE-DEPRECATION NOTICE<\/strong><\/p>\n<p>Instead of this deprecated and no longer-maintained boilerplate, I now recommend you to use my new toolkit called \ud83d\udd25 \u269b\u200f \ud83d\udce6 <a href=\"https:\/\/github.com\/ahmadawais\/create-guten-block\" rel=\"nofollow noopener\" target=\"_blank\"><code>create-guten-block<\/code> \u2192<\/a><\/p>\n<hr \/>\n<table width='100%'>\n    <tr>\n        <td align='left' width='100%' colspan='2'>\n            <strong>Gutenberg Boilerplate<\/strong><br \/>\n            An easy to understand and heavily documented\ufe0f WordPress Gutenberg Boilerplate!\n        <\/td>\n    <\/tr>\n    <tr>\n        <td>\n            A FOSS (Free & Open Source Software) project. Maintained by <a href=\"https:\/\/github.com\/ahmadawais\" rel=\"nofollow noopener\" target=\"_blank\">@AhmadAwais<\/a>.\n        <\/td>\n        <td align='center'>\n            <a href=\"https:\/\/AhmadAwais.com\/\" rel=\"nofollow noopener\" target=\"_blank\">\n                <img src=\"https:\/\/i.imgur.com\/Asg4d3k.png\" width=\"100\" alt=\"\">\n            <\/a>\n        <\/td>\n    <\/tr>\n<\/table>\n\n<p><a href=\"https:\/\/pay.paddle.com\/checkout\/515568\" rel=\"nofollow noopener\" target=\"_blank\"><img src=\"https:\/\/img.shields.io\/badge\/%F0%9F%94%A5%20Support%20Gutenberg%20Boilerplate-%E2%93%A6-brightgreen.svg?style=flat-square\" alt=\"Gutenberg-Boilerplate\" \/><\/a> <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/\" rel=\"nofollow noopener\" target=\"_blank\"><img src=\"https:\/\/img.shields.io\/wordpress\/v\/akismet.svg?maxAge=2592000&amp;style=flat-square&amp;label=WordPress\" alt=\"\"><\/a> <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/releases\" rel=\"nofollow noopener\" target=\"_blank\"><img src=\"https:\/\/img.shields.io\/github\/release\/ahmadawais\/Gutenberg-Boilerplate.svg?maxAge=2592000&amp;style=flat-square&amp;label=Version\" alt=\"GitHub release\" \/><\/a> <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/stargazers\" rel=\"nofollow noopener\" target=\"_blank\"><img src=\"https:\/\/img.shields.io\/github\/stars\/ahmadawais\/Gutenberg-Boilerplate.svg?style=social&amp;label=Star&amp;maxAge=200&amp;cache=buster\" alt=\"\"><\/a><\/p>\n<p><img src=\"https:\/\/i.imgur.com\/P5rw2pS.jpg\" alt=\"gutenberg-boilerpalte\" \/>\nBuild your first Gutenberg Editor block! A boilerplate to build WP Gutenberg blocks and stuff! \u270a<\/p>\n<h2>\u26a1\ufe0f Getting Started<\/h2>\n<ol>\n<li>\u2705 Install &amp; activate the <a href=\"https:\/\/wordpress.org\/plugins\/gutenberg\/\" rel=\"nofollow noopener\" target=\"_blank\">Gutenberg<\/a> WordPress plugin<\/li>\n<li>\u2705 Then download and install\/activate this <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/archive\/master.zip\" rel=\"nofollow noopener\" target=\"_blank\">Gutenberg Boilerplate plugin<\/a> \u2190 Just click this link to download.<\/li>\n<li>\ud83d\ude4a All blocks added by this boilerplate are prefixed with <code>GB<\/code> as in Gutenberg-Boilerplate. Take a look at the GIFs below to see how to try 'em out.<\/li>\n<li>\ud83c\udfaf To try the ESNext block, i.e. <code>02-basic-esnext<\/code> go to it's directory i.e.  <code>gutenberg-boilerpalte\/block\/02-basic-esnext<\/code> and run <code>npm install<\/code>. Make sure you have <a href=\"https:\/\/nodejs.org\/en\/download\/\" rel=\"nofollow noopener\" target=\"_blank\">Node and npm installed<\/a>. Then in the <code>02-basic-esnext<\/code> directory run <code>npm run dev<\/code> for development or <code>npm run build<\/code> to build the production code.<\/li>\n<li>\ud83d\udcaf Now read the source code to learn how to build blocks. It's heavily documented. <\/li>\n<\/ol>\n<blockquote>\n<p>RECOMMENDED READING: Read the blog post I wrote \u2192 <a href=\"https:\/\/ahmadawais.com\/gutenberg-boilerplate\/\" target=\"_blank\" rel=\"noopener\">Gutenberg Boilerplate For Third-Party Custom Blocks<\/a>.<\/p>\n<\/blockquote>\n<h2>\u26a1\ufe0f What Can You Learn?<\/h2>\n<p>This is a <code>todo<\/code> list for this boilerplate which also states the progress of what you can learn from it.<\/p>\n<ul>\n<li>[x] BLOG POST: <a href=\"https:\/\/ahmadawais.com\/gutenberg-boilerplate\/\" target=\"_blank\" rel=\"noopener\">Gutenberg Boilerplate For Third-Party Custom Blocks<\/a>.<\/li>\n<li>[X] <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/tree\/master\/block\/01-basic\" rel=\"nofollow noopener\" target=\"_blank\">Build a Custom Gutenberg Block<\/a> \u2014 with custom CSS for editor and front end.<\/li>\n<li>[x] <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/tree\/master\/block\/02-basic-esnext\" rel=\"nofollow noopener\" target=\"_blank\">Build a Custom Gutenberg Block<\/a> \u2014 with <code>ES6<\/code> or <code>ESNext<\/code> and a <code>Webpack<\/code> build process.<\/li>\n<li>[x] <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/tree\/master\/block\/03-block-editable\" rel=\"nofollow noopener\" target=\"_blank\">Build a Custom Gutenberg Block<\/a> \u2014 with <code>editable<\/code> content.<\/li>\n<li>[x] <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/tree\/master\/block\/04-tweet\" rel=\"nofollow noopener\" target=\"_blank\">Build a Custom Gutenberg Block<\/a> \u2014 to click Tweet the contents of that block.<\/li>\n<li>[ ] Build a Custom Gutenberg Block \u2014 with <code>editable<\/code> content and custom <code>toolbars<\/code>.<\/li>\n<li>[ ] Build a Custom Gutenberg Block \u2014 with a card layout <code>editable<\/code> + <code>non-ediatable<\/code> content (text + media).<\/li>\n<li>[ ] Maybe build a video series on Gutenberg development!<\/li>\n<\/ul>\n<h2>\ud83c\udf69 GIF Me Some Proof!<\/h2>\n<p>Sure thing! Here are a few examples of how you can use this WordPress plugin. When you install it after installing the Gutenberg plugin, this plugin gives you following four additional blocks.<\/p>\n<h3>\ud83d\udce6 Block #1<\/h3>\n<p><a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/tree\/master\/block\/01-basic\" rel=\"nofollow noopener\" target=\"_blank\">Build a Custom Gutenberg Block<\/a> \u2014 with custom CSS for editor and front end.<\/p>\n<p><img src=\"https:\/\/on.ahmda.ws\/oESb\/c\" alt=\"block1\" \/><\/p>\n<h3>\ud83d\udce6 Block #2<\/h3>\n<p><a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/tree\/master\/block\/02-basic-esnext\" rel=\"nofollow noopener\" target=\"_blank\">Build a Custom Gutenberg Block<\/a> \u2014 with <code>ES6<\/code> or <code>ESNext<\/code> and a <code>Webpack<\/code> build process.<\/p>\n<p>\ud83c\udfaf To try the ESNext block, i.e. <code>02-basic-esnext<\/code> go to it's directory i.e.  <code>gutenberg-boilerpalte\/block\/02-basic-esnext<\/code> and run <code>npm install<\/code>. Make sure you have <a href=\"https:\/\/nodejs.org\/en\/download\/\" rel=\"nofollow noopener\" target=\"_blank\">Node and npm installed<\/a>. Then in the <code>02-basic-esnext<\/code> directory run <code>npm run dev<\/code> for development or <code>npm run build<\/code> to build the production code.<\/p>\n<p><img src=\"https:\/\/on.ahmda.ws\/oFDW\/c\" alt=\"block2\" \/><\/p>\n<h3>\ud83d\udce6 Block #3<\/h3>\n<p><a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/tree\/master\/block\/03-block-editable\" rel=\"nofollow noopener\" target=\"_blank\">Build a Custom Gutenberg Block<\/a> \u2014 with <code>editable<\/code> content.<\/p>\n<p><img src=\"https:\/\/on.ahmda.ws\/oF8M\/c\" alt=\"block3\" \/><\/p>\n<h3>\ud83d\udce6 Block #4<\/h3>\n<p><a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/tree\/master\/block\/04-tweet\" rel=\"nofollow noopener\" target=\"_blank\">Build a Custom Gutenberg Block<\/a> \u2014 to click Tweet the contents of that block.<\/p>\n<p><img src=\"https:\/\/on.ahmda.ws\/oFEA\/c\" alt=\"block3\" \/><\/p>\n<h2>\u26a1\ufe0f License &amp; Attribution<\/h2>\n<p>Code is licensed under GPL v3.0. The content and documentation is copyrighted to the WordPress Gutenberg team and WGA - AhmadAwais.com (especially the content in the blog post). I am still making up my mind with how Gutenberg will fit in the WordPress core. There are so many things which are both good and bad about it. So, instead of ranting about it, I wanted to do something more productive. I went ahead, studied the source code and received a lot of help from <a href=\"https:\/\/github.com\/wordpress\/gutenberg\" rel=\"nofollow noopener\" target=\"_blank\">Gutenberg<\/a> project and its contributors (Matias Ventura, James Nylen, Riad Benguella, Andrew Duthie, Joen, etc.) to finally build this. I started with three different repos which now co-exist as the Gutenberg examples and added more examples and documentation, using the Gutenberg code as a reference. Thanks to the Gutenberg team for a lot of help along the way.<\/p>\n<p>I also wrote about it <a href=\"https:\/\/ahmadawais.com\/gutenberg-boilerplate\/\" target=\"_blank\" rel=\"noopener\">Gutenberg Boilerplate For Third-Party Custom Blocks<\/a>.<\/p>\n<hr \/>\n<p>\ud83d\ude4c Hello, from the <a href=\"https:\/\/TheDevCouple.com\" rel=\"nofollow noopener\" target=\"_blank\">TheDevCouple<\/a>! I (<a href=\"https:\/\/AhmadAwais.com\/\" rel=\"nofollow noopener\" target=\"_blank\">Ahmad Awais<\/a>) am a Full Stack Web Developer and a regular core contributor at WordPress. My wife (<a href=\"https:\/\/MaedahBatool.com\/\" rel=\"nofollow noopener\" target=\"_blank\">Maedah Batool<\/a>) is a WordPress Journalist\/Dev\/Core Contributor. If you'd like to get insights into professional full stack development, DevOps, WordPress community news, growing up a family, building and bootstrapping a business then subscribe to our premium newsletter called \u21a3 <a href=\"https:\/\/WPTakeaway.club\" rel=\"nofollow noopener\" target=\"_blank\">The WordPress Takeaway<\/a>!<\/p>\n<hr \/>\n<p>\ud83c\udfa9 <a href=\"https:\/\/pay.paddle.com\/checkout\/515568\" rel=\"nofollow noopener\" target=\"_blank\"><strong>Support Ahmad's Open Source Projects!<\/strong><\/a><\/p>\n<p>If you'd like me to keep producing professional free and open source software (FOSS). Consider <a href=\"https:\/\/pay.paddle.com\/checkout\/515568\" rel=\"nofollow noopener\" target=\"_blank\">paying for an hour of my time<\/a>. I'll spend two hours on open source for each contribution.<\/p>\n<hr \/>\n<p>It&#8217;s free and open source. Issues\/PR&#8217;s are welcomed on GitHub.\u00a0Let me know what you think about this \ud83d\ude42<\/p>\n<blockquote><p>\ud83d\ude80 <a href=\"https:\/\/github.com\/ahmadawais\/Gutenberg-Boilerplate\/\" rel=\"nofollow noopener\" target=\"_blank\">GITHUB: \u2605 773 \u2442 88 \u2192<\/a><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to build custom Gutenberg WordPress editor blocks for your themes and plugins. A boilerplate which is heavily documented and will help you kick-start with extending Gutenberg with ReactJS, ESNext, with Webpack, etc.\u00a0<\/p>\n","protected":false},"author":1,"featured_media":1330,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":""},"categories":[6],"tags":[28],"coauthors":[84],"jetpack_featured_media_url":"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/07\/gb3.jpg","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts\/1329"}],"collection":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/comments?post=1329"}],"version-history":[{"count":1,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts\/1329\/revisions"}],"predecessor-version":[{"id":3442,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts\/1329\/revisions\/3442"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/media\/1330"}],"wp:attachment":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/media?parent=1329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/categories?post=1329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/tags?post=1329"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/coauthors?post=1329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}