{"id":69193,"date":"2019-01-21T09:00:04","date_gmt":"2019-01-21T15:00:04","guid":{"rendered":"https:\/\/wpengine.com\/?p=69193"},"modified":"2019-01-17T16:31:34","modified_gmt":"2019-01-17T22:31:34","slug":"steps-and-tips-for-building-your-first-gutenberg-block-plugin","status":"publish","type":"post","link":"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/","title":{"rendered":"Steps and Tips for Building Your First Gutenberg Block Plugin"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">The new editing experience, Gutenberg, provides users with a fresh and exciting writing experience via rich content and intuitive capabilities. While the old editor required shortcodes, HTML, and custom post types to make a vision take form, the new editor works more like puzzle-strategic, block-like elements are built individually and come together to create the final markup. There are blocks for almost everything: paragraphs, lists, buttons, etc. Additionally, users have the ability to create templates within the editor via reusable blocks. Since its release last month, the editor has enhanced the appeal WordPress for content creators and future-proofed the CMS for years to come.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As Gutenberg continues to become more sophisticated and more bugs are expelled, more WordPress users will begin to use the new editor and the possibilities with development will expand. Leaders of the project have reiterated that the editor is just the beginning, the goal was always to expand Gutenberg to widgets, menus, and beyond. If they haven\u2019t already, developers will need to become familiar with JavaScript and React. The aim of this article is to provide tips to developers for the creation of their first block.<\/span><\/p>\n<h2><strong>Getting to Know JavaScript<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">With the exception of bringing the files in via PHP, Gutenberg blocks are built almost entirely in JavaScript. An abstraction layer is built over React using Javascript, limiting the direct interaction with the <\/span><a href=\"https:\/\/reactjs.org\/\"><span style=\"font-weight: 400;\">React JavaScript Library<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h3><strong>Choose a Version <\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">JavaScript has been through a bit of its own evolution-you\u2019ll need to decide what version you want to work with (ECMAScript 5 or newer). Keep in mind that more recent versions will require extra effort to ensure compatibility with all browsers. ES% is universally supported by all browsers, ES6 came out in 2015 and since then new iterations have come out every year.<\/span><\/p>\n<h3><strong>JSX<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">JSX, another component in building Gutenberg blocks, \u00a0is a preprocessor step that adds XML syntax to JavaScript and looks and feels very similar to writing XML or HTML tags. You\u2019ll need a package manager like <\/span><a href=\"https:\/\/nodejs.org\/en\/\"><span style=\"font-weight: 400;\">Node<\/span><\/a><span style=\"font-weight: 400;\"> or <\/span><a href=\"https:\/\/webpack.js.org\/\"><span style=\"font-weight: 400;\">Webpack<\/span><\/a><span style=\"font-weight: 400;\"> for compilation purposes. Because JavaScript will continue to evolve, it\u2019s important to understand React and JSX.<\/span><\/p>\n<h3><strong>Get Comfortable with Existing Components <\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">There are existing components for almost anything you want to do in JSX. If you\u2019re hard-coding an input, there\u2019s probably an easier way to do it. A handy link to documentation on the available components can be found <\/span><a href=\"https:\/\/wordpress.org\/gutenberg\/handbook\/designers-developers\/developers\/components\/\"><span style=\"font-weight: 400;\">here<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><strong>Getting Started with Building a Gutenberg Block Plugin<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">After you\u2019ve become familiarized with JavaScript and you\u2019ve downloaded Node or Webpack, you can begin experimenting with building a block plugin. Anything that creates content, like a block, will need to be developed in the form of a plugin in order for it to stay active as you change themes and experiment with new components on your site.<\/span><\/p>\n<h3><strong>Install Create-Guten-Block<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">An excellent resource for creating your block is the Create-Guten-Block toolkit built by Ahmad Awais. <\/span><a href=\"https:\/\/github.com\/ahmadawais\/create-guten-block\"><span style=\"font-weight: 400;\">Create-Guten-Block<\/span><\/a><span style=\"font-weight: 400;\"> is a zero-configuration developer toolkit for building Gutenberg block contained in plugins. This is an initial shortcut step that will allow you to bypass the need for a deep understanding of the technology behind block development; it takes away a lot of the stress of a build process and allows you to focus on the functionality you wish to build. The code is widely documented so it is encouraged to explore the files read through the inline comments to gain an understanding of the code.<\/span><\/p>\n<h3><b>Creating a Plugin that Registers a Block<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Begin by setting up a local installation on your machine. You can use <\/span><a href=\"https:\/\/varyingvagrantvagrants.org\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">VVV<\/span><\/a><span style=\"font-weight: 400;\">. Navigate to the plugins directory and run npx create-guten-block plus the name of your block (your choice). After that, start it up. This will take a couple of minutes to install. <\/span><\/p>\n<p><code>npx create-guten-block<br \/>\ncd my-block<br \/>\nnpm start\u00a0<\/code><\/p>\n<h2>Important Files to Know<\/h2>\n<p>After firing it up, you&#8217;ll find code detailing aspects of create-guten-block files that you might not be familiar with. It&#8217;s important to be a little familiar with the plugin structure.<\/p>\n<p><strong>plugin.php<\/strong><\/p>\n<p>Use this to define and name your plugin. Along with changing the renaming the file to match your plugin, you&#8217;ll want to list yourself as the author and update your plugin&#8217;s description information.<\/p>\n<p><strong>README.md<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">This file contains basic info about create-guten-block. Use this as a guide to configuring your local development workflow.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>block\/block.js<\/strong> <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The details all the JavaScript for a block. <\/span><\/p>\n<p><strong>src\/blocks.js <\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Lists all blocks related JavaScript files. <\/span><\/p>\n<p><strong>block\/editor.scss <\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Sass partial for styles that are specific to the editor itself. <\/span><\/p>\n<p><strong>block\/style.scss <\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Sass partial for styles specific to the front end.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">More Resources for Getting Started with React <\/span><\/h2>\n<p><span style=\"font-weight: 400;\">React is the go-to strategy for creating scalable, real-world applications. Thankfully, there are a plethora of resources for getting started and using that knowledge in WordPress development: <\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><a href=\"https:\/\/torquemag.io\/2018\/10\/react-basics-for-wordpress-developers\/\"><span style=\"font-weight: 400;\">React Basics for WordPress Developers <\/span><\/a><span style=\"font-weight: 400;\">&#8211; This is an excellent resource for learning the basics of React and applying that knowledge to Gutenberg development. <\/span><\/li>\n<li style=\"font-weight: 400;\"><a href=\"https:\/\/frontendmasters.com\/courses\/react\/\"><span style=\"font-weight: 400;\">Complete Intro to React, v3 (feat. Redux, Router &amp; Flow)<\/span><\/a><span style=\"font-weight: 400;\"> &#8211; This is a paid course that will really give you a deep dive into React and how to associated tools.<\/span><\/li>\n<li style=\"font-weight: 400;\"><a href=\"https:\/\/reactforbeginners.com\/\"><span>React for Beginners<\/span><\/a><span>&#8211; This course provides hands-on instruction for learning and developing with React. Developers of any level will find this course helpful if trying to get more comfortable with React.<\/span><\/li>\n<\/ul>\n<p><i><span style=\"font-weight: 400;\">Stay tuned to the WP Engine blog for helpful WordPress tips related to the new editor and more! <\/span><\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The new editing experience, Gutenberg, provides users with a fresh and exciting writing experience via rich content and intuitive capabilities. While the old editor required shortcodes, HTML, and custom post types to make a vision take form, the new editor works more like puzzle-strategic, block-like elements are built individually and come together to create the<span class=\"tile__ellipses\">&hellip;<\/span><span class=\"tile__ellipses--animated\"><\/span><\/p>\n","protected":false},"author":173,"featured_media":69737,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5,100,81],"tags":[],"class_list":["post-69193","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","category-troubleshooting-wordpress","category-wordpress-community"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Steps and Tips for Building Your First Gutenberg Block Plugin<\/title>\n<meta name=\"description\" content=\"Want to get started creating your own custom blocks in the new WordPress editor? This article will provide you with the steps you need to get started.\" \/>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Steps and Tips for Building Your First Gutenberg Block Plugin\" \/>\n<meta property=\"og:description\" content=\"Want to get started creating your own custom blocks in the new WordPress editor? This article will provide you with the steps you need to get started.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Engine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wpengine\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-21T15:00:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-01-17T22:31:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wpengine.com\/resources\/wp-content\/uploads\/2019\/01\/Gutenbergblocks_hero.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Alyssa Cuda\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@wpengine\" \/>\n<meta name=\"twitter:site\" content=\"@wpengine\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alyssa Cuda\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/\",\"url\":\"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/\",\"name\":\"Steps and Tips for Building Your First Gutenberg Block Plugin\",\"isPartOf\":{\"@id\":\"https:\/\/wpengine.com\/resources\/#website\"},\"datePublished\":\"2019-01-21T15:00:04+00:00\",\"dateModified\":\"2019-01-17T22:31:34+00:00\",\"author\":{\"@id\":\"https:\/\/wpengine.com\/resources\/#\/schema\/person\/2e7ae57f60120ddae3dc029b03cfa81a\"},\"description\":\"Want to get started creating your own custom blocks in the new WordPress editor? This article will provide you with the steps you need to get started.\",\"breadcrumb\":{\"@id\":\"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wpengine.com\/resources\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Steps and Tips for Building Your First Gutenberg Block Plugin\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wpengine.com\/resources\/#website\",\"url\":\"https:\/\/wpengine.com\/resources\/\",\"name\":\"WP Engine\",\"description\":\"Managed Hosting for WordPress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wpengine.com\/resources\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wpengine.com\/resources\/#\/schema\/person\/2e7ae57f60120ddae3dc029b03cfa81a\",\"name\":\"Alyssa Cuda\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wpengine.com\/resources\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9031010d4260959c1fffb0b199ffa33db42a2b53baa3bf9927a289237e907252?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9031010d4260959c1fffb0b199ffa33db42a2b53baa3bf9927a289237e907252?s=96&d=mm&r=g\",\"caption\":\"Alyssa Cuda\"},\"description\":\"Alyssa is a Content Specialist at WP Engine. If she\u2019s not searching for a swimming hole to escape the heat in, you can usually find her baking something caloric or reading.\u2002\u2002\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Steps and Tips for Building Your First Gutenberg Block Plugin","description":"Want to get started creating your own custom blocks in the new WordPress editor? This article will provide you with the steps you need to get started.","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"Steps and Tips for Building Your First Gutenberg Block Plugin","og_description":"Want to get started creating your own custom blocks in the new WordPress editor? This article will provide you with the steps you need to get started.","og_url":"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/","og_site_name":"WP Engine","article_publisher":"https:\/\/www.facebook.com\/wpengine","article_published_time":"2019-01-21T15:00:04+00:00","article_modified_time":"2019-01-17T22:31:34+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/wpengine.com\/resources\/wp-content\/uploads\/2019\/01\/Gutenbergblocks_hero.jpg","type":"image\/jpeg"}],"author":"Alyssa Cuda","twitter_card":"summary_large_image","twitter_creator":"@wpengine","twitter_site":"@wpengine","twitter_misc":{"Written by":"Alyssa Cuda","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/","url":"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/","name":"Steps and Tips for Building Your First Gutenberg Block Plugin","isPartOf":{"@id":"https:\/\/wpengine.com\/resources\/#website"},"datePublished":"2019-01-21T15:00:04+00:00","dateModified":"2019-01-17T22:31:34+00:00","author":{"@id":"https:\/\/wpengine.com\/resources\/#\/schema\/person\/2e7ae57f60120ddae3dc029b03cfa81a"},"description":"Want to get started creating your own custom blocks in the new WordPress editor? This article will provide you with the steps you need to get started.","breadcrumb":{"@id":"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wpengine.com\/resources\/steps-and-tips-for-building-your-first-gutenberg-block-plugin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wpengine.com\/resources\/"},{"@type":"ListItem","position":2,"name":"Steps and Tips for Building Your First Gutenberg Block Plugin"}]},{"@type":"WebSite","@id":"https:\/\/wpengine.com\/resources\/#website","url":"https:\/\/wpengine.com\/resources\/","name":"WP Engine","description":"Managed Hosting for WordPress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wpengine.com\/resources\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/wpengine.com\/resources\/#\/schema\/person\/2e7ae57f60120ddae3dc029b03cfa81a","name":"Alyssa Cuda","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/resources\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9031010d4260959c1fffb0b199ffa33db42a2b53baa3bf9927a289237e907252?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9031010d4260959c1fffb0b199ffa33db42a2b53baa3bf9927a289237e907252?s=96&d=mm&r=g","caption":"Alyssa Cuda"},"description":"Alyssa is a Content Specialist at WP Engine. If she\u2019s not searching for a swimming hole to escape the heat in, you can usually find her baking something caloric or reading.\u2002\u2002"}]}},"acf":[],"_links":{"self":[{"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/posts\/69193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/users\/173"}],"replies":[{"embeddable":true,"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/comments?post=69193"}],"version-history":[{"count":0,"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/posts\/69193\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/media\/69737"}],"wp:attachment":[{"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/media?parent=69193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/categories?post=69193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpengine.com\/resources\/wp-json\/wp\/v2\/tags?post=69193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}