SlideShare a Scribd company logo
GETTING STARTED WITH
GUTENBERG
DEVELOPMENTJason Yingling (@jason_yingling)
jasonyingling.me
GUTENBERG
TODAY
Active development - Github
Feature Plugin on WordPress.org
Coming in WordPress 5.0
Release date: TBD 2018 🤞
TABLE OF
CONTENTS
What are Blocks
Best Practices
Enqueueing Scripts
JavaScript for Gutenberg
The Block API
Where to Learn More
GUTENBERG
BLOCKS
“
”
The way in which themes and plugins
can add their own functionality to
expand on the post editor.
BLOCKS IN THE
EDITOR
BLOCKS IN THE
FRONT END
BLOCK
OBJECT TREE
While editing a post with the Gutenberg editor, block
information is stored in memory in a “tree of objects”.
BLOCKS IN THE
DATABASE
HTML comments are used to denote blocks in the post
markup for conversion back to editable blocks in the
Gutenberg editor.
THEME SUPPORT
BEST
PRACTICES
WIDE AND FULL
IMAGE ALIGNMENTS
Gutenberg adds two new image alignments alignwide
and alignfull.
Themes must declare theme support to enable them.
STYLING THE ALIGNMENTS
METHOD 1
Breaking alignfull and alignwide out of a limited width
parent.
STYLING THE ALIGNMENTS
METHOD 2
alignfull and alignwide inside a full-width parent.
DEFAULT
COLOR PALETTE
The color palette allows theme developers to set
a collection of preset colors to choose from in the
block editor.
BLOCK DEVELOPMENT
BEST
PRACTICES
INCLUDING BLOCKS
PLUGINS OR THEMES
“
”
The general rule of thumb for including
functionality in plugins or themes is to keep
themes to the presentation of content and
use plugins for functionality.
BEST PRACTICES:
FILE STRUCTURE
File structures can vary and this particular structure is not a requirement.
BEST PRACTICES:
NAMING BLOCKS
Blocks require the name to be structured as
namespace/block-name.
namespace will be your plugin name.
block-name can only use lowercase alphanumeric
characters, dashes, and must begin with a letter.
BEST PRACTICES:
TRANSLATION
Strings in JavaScript can be made translatable with
similar functions as used in PHP translations.
BLOCK DEVELOPMENT
ENQUEUEING
SCRIPTS
ENQUEUEING SCRIPTS
HOOKS
enqueue_block_editor_assets
Hook for enqueueing scripts and styles in the admin
editor only.
enqueue_block_assets
Hook for enqueueing scripts and styles in both the
admin editor and the frontend.
Use with wp_enqueue_script and wp_enqueue_style
WHAT TO ENQUEUE
EDITOR ONLY
Main JavaScript for registering and
editing blocks
Styles that are only relevant in the
context of the editor.
enqueue_block_editor_assets
WHAT TO ENQUEUE
EDITOR ONLYenqueue_block_editor_assets
WHAT TO ENQUEUE
EDITOR AND FRONTEND
JavaScript needed to function on
the frontend
Main styles for final output of the
block
enqueue_block_assets
WHAT TO ENQUEUE
EDITOR AND FRONTENDenqueue_block_assets
AN ALTERNATE METHOD FOR
ENQUEUEING
A slightly different approach to enqueueing
A NOTE ON
DEPENDENCIES
Gutenberg comes with several JavaScript libraries
that can kick-start your block building.
At minimum when enqueueing your scripts you should
list wp-blocks and wp-element as dependencies
wp-components and wp-i18n are optional but very
useful libraries
JAVASCRIPT FOR
GUTENBERG
JAVASCRIPT LIBRARIES
WP.ELEMENT
Abstraction layer atop React
Used for creating elements
Protects the WordPress Way
Access to createElement and
render functions
Handle: wp-element
JAVASCRIPT LIBRARIES
WP.BLOCKS
Gives access to components and
functions used for building blocks
registerBlockType lives here
BlockControls and RichText
components are made available
Handle: wp-blocks
JAVASCRIPT LIBRARIES
WP.EDITOR
BlockControls and RichText
components are made available
As of 3.1.0
5 days ago
Handle: wp-editor
JAVASCRIPT LIBRARIES
WP.COMPONENTS
Additional components that can be
used in block creation
tooltips, popovers, and spinners
are a few components that can be
found
Full List on Github
Handle: wp-components
JAVASCRIPT LIBRARIES
WP.I18N
Contains internationalization
functions for JavaScript
Similar to the PHP __()
internationalization function
Handle: wp-i18n
MODERN JAVASCRIPT IN
GUTENBERG
ES6+
JSX
React
WHAT IS MODERN JS
ES6+ (ECMASCRIPT)
ES5 - 2009 ( Standard JS )
ES6+ - 2015 ( Modern JS / Yearly )
ES7 - 2016
ES8 - 2017
ES Next - The next version
WHAT IS MODERN JS
JSX
A syntax for writing HTML like markup in JavaScript
WHAT IS MODERN JS
REACT
A JavaScript framework for building user interfaces
using components.
Components are essentially custom HTML elements
with their own functionality.
USING MODERN JS
BUILD TOOLS
Tools for taking modern JS and outputting browser
compatible JS.
Babel, webpack, etc.
Babel
BUILDING BLOCKS
BLOCK API
BLOCK API
INDEX.JS
Import dependencies
Make functionality from JavaScript
libraries available to your block
Register your block
BLOCK API
REGISTER BLOCK
TYPE
The function for registering a block.
Takes two arguments: block name
and a block configuration object
edit and save functions are where
the magic happens
BLOCK CONFIG
TITLE
The title for your block shown to the
user when inserting a block
BLOCK CONFIG
DESCRIPTION (OPTIONAL)
Short description for your block
BLOCK CONFIG
CATEGORY
Helps users discover and browse
blocks. Core categories are common,
formatting, layout, widgets, and
embed
BLOCK CONFIG
ICON (OPTIONAL)
A Dashicon or custom SVG used to
identify your block in the editor
BLOCK CONFIG
KEYWORDS (OPTIONAL)
Additional keywords (up to 3) used for
discovering blocks
BLOCK CONFIG
ATTRIBUTES (OPTIONAL)
Allow for extracting values from saved
post content for use in the JavaScript
representation of a block
BLOCK CONFIG
EDIT
The edit function handles how your block is displayed
in the context of the editor. It receives the attributes,
className, and isSelected properties.
BLOCK CONFIG
SAVE
The save function handles how the attributes of your
block are combined into the final markup.
BLOCK CONFIG
RICHTEXT API
A component for rendering a rich contenteditable
input for blocks.
Provides users the
option to add emphasis
or links to content.
Properties Available
BLOCK CONFIG
DYNAMIC BLOCKS
For blocks that need to pull information from the
database you’ll use a
PHP callback.
For the editor display
Gutenberg exposes
the RestAPI with
withAPIData.
PUTTING IT ALL
TOGETHER
STEPS TO
GET STARTED
Setup a plugin
Enqueue assets
Setup a compiler
Write the code
Run a build process
QUICK START
CREATE-GUTEN-
BLOCKhttps://github.com/ahmadawais/create-guten-block
GUTENBERG DEVELOPMENT
RESOURCES
Gutenberg.courses
Gutenberg.news
Create Guten Block
Gutenberg Handbook
Gutenberg Repository
Make.WordPress.org
GUTENBERG DEVELOPMENT
QUESTIONS
Twitter: @jason_yingling
Email: jason@jasonyingling.me

More Related Content

What's hot (20)

PPTX
AngularJS 2.0
Boyan Mihaylov
 
PDF
Modern Web Application Development Workflow - EclipseCon Europe 2014
Stéphane Bégaudeau
 
PPTX
Web Components the best marriage for a PWA
Manuel Carrasco Moñino
 
PPTX
UI Customization in AEM 6.0
Gilles Knobloch
 
PDF
CIRCUIT 2015 - Content API's For AEM Sites
ICF CIRCUIT
 
PDF
Introduction to AngularJS
Aldo Pizzagalli
 
PPTX
Angular Js Advantages - Complete Reference
EPAM Systems
 
PPTX
Building assets on the fly with Node.js
Acquisio
 
PDF
User Interface customization for AEM 6
Damien Antipa
 
PDF
AEM 6.1 User Interface Customization
Christian Meyer
 
PPTX
React JS Belgium Touch Base - React, Flux, React Native
Philos.io
 
PPT
Using Features
Alexandru Badiu
 
PDF
Deview 2013 mobile browser internals and trends_20131022
NAVER D2
 
PDF
Android Chromium Rendering Pipeline
Hyungwook Lee
 
PDF
Web components are the future of the web - Take advantage of new web technolo...
Marios Fakiolas
 
PDF
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Jeado Ko
 
PDF
Angular.js - JS Camp UKraine 2013
Max Klymyshyn
 
PPTX
Angularjs PPT
Amit Baghel
 
PPTX
AEM 6.0 - Author UI Customization & Features
Abhinit Bhatnagar
 
AngularJS 2.0
Boyan Mihaylov
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Stéphane Bégaudeau
 
Web Components the best marriage for a PWA
Manuel Carrasco Moñino
 
UI Customization in AEM 6.0
Gilles Knobloch
 
CIRCUIT 2015 - Content API's For AEM Sites
ICF CIRCUIT
 
Introduction to AngularJS
Aldo Pizzagalli
 
Angular Js Advantages - Complete Reference
EPAM Systems
 
Building assets on the fly with Node.js
Acquisio
 
User Interface customization for AEM 6
Damien Antipa
 
AEM 6.1 User Interface Customization
Christian Meyer
 
React JS Belgium Touch Base - React, Flux, React Native
Philos.io
 
Using Features
Alexandru Badiu
 
Deview 2013 mobile browser internals and trends_20131022
NAVER D2
 
Android Chromium Rendering Pipeline
Hyungwook Lee
 
Web components are the future of the web - Take advantage of new web technolo...
Marios Fakiolas
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Jeado Ko
 
Angular.js - JS Camp UKraine 2013
Max Klymyshyn
 
Angularjs PPT
Amit Baghel
 
AEM 6.0 - Author UI Customization & Features
Abhinit Bhatnagar
 

Similar to Getting Started with Gutenberg Development (20)

PDF
Gutenberg (WidgiLabs Training Sessions)
Nuno Morgadinho
 
PPT
Engage - Expanding XPages with Bootstrap Plugins for ultimate usability
Johnny Oldenburger
 
PDF
Implementing auto complete using JQuery
Bhushan Mulmule
 
PPTX
Build and save your own Gutenberg Block Patterns
Plasterdog Web Design
 
PPTX
Web components Introduction
Eugenio Romano
 
PDF
Blockity McBlock Blocks, Oh My!
Evan Mullins
 
PPTX
BEM methodology overview
Oleksii Prohonnyi
 
PPTX
Webpack/Parcel: What’s Happening Behind the React App?
Talentica Software
 
PDF
Fewd week2 slides
William Myers
 
PPT
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
Sean Burgess
 
PPTX
Custom gutenberg block development with React
Imran Sayed
 
PPTX
Lightning web components
Cloud Analogy
 
PPTX
Building services using windows azure
Suliman AlBattat
 
PDF
No gEEk? No Problem!
carolinecblaker
 
PPT
Netbeans 6.1 Talk
Angad Singh
 
PDF
BEM It! for Brandwatch
Max Shirshin
 
PPT
Beginner's guide to drupal
mayank.grd
 
PPTX
slides oif mlsa oigf fhdhd cgdgd gggd bdg.pptx
PRINCEOJHA11
 
PPTX
Bootstrap 5 whats new
Sandun Perera
 
PPTX
Modern JavaScript Talk
Derek Binkley
 
Gutenberg (WidgiLabs Training Sessions)
Nuno Morgadinho
 
Engage - Expanding XPages with Bootstrap Plugins for ultimate usability
Johnny Oldenburger
 
Implementing auto complete using JQuery
Bhushan Mulmule
 
Build and save your own Gutenberg Block Patterns
Plasterdog Web Design
 
Web components Introduction
Eugenio Romano
 
Blockity McBlock Blocks, Oh My!
Evan Mullins
 
BEM methodology overview
Oleksii Prohonnyi
 
Webpack/Parcel: What’s Happening Behind the React App?
Talentica Software
 
Fewd week2 slides
William Myers
 
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
Sean Burgess
 
Custom gutenberg block development with React
Imran Sayed
 
Lightning web components
Cloud Analogy
 
Building services using windows azure
Suliman AlBattat
 
No gEEk? No Problem!
carolinecblaker
 
Netbeans 6.1 Talk
Angad Singh
 
BEM It! for Brandwatch
Max Shirshin
 
Beginner's guide to drupal
mayank.grd
 
slides oif mlsa oigf fhdhd cgdgd gggd bdg.pptx
PRINCEOJHA11
 
Bootstrap 5 whats new
Sandun Perera
 
Modern JavaScript Talk
Derek Binkley
 
Ad

More from Jason Yingling (14)

PDF
WordPress Security Best Practices
Jason Yingling
 
PPTX
Installing WP-CLI locally
Jason Yingling
 
PPTX
Plugin development
Jason Yingling
 
PPTX
Introducing CSS Grid
Jason Yingling
 
PPTX
Customizing the WordPress Customizer
Jason Yingling
 
PDF
Battling Google PageSpeed Insights
Jason Yingling
 
PPTX
Putting the Develop in Development
Jason Yingling
 
PPTX
Getting to Know Underscores
Jason Yingling
 
PPTX
Speeding Up WordPress sites
Jason Yingling
 
PPTX
Creating Dynamic Sidebars & Widgets in WordPress
Jason Yingling
 
PPTX
WordPress Template hierarchy
Jason Yingling
 
PPTX
Design todevelop
Jason Yingling
 
PPTX
Ithemes presentation
Jason Yingling
 
PPTX
Building Flexible Sites with Advanced Custom Fields
Jason Yingling
 
WordPress Security Best Practices
Jason Yingling
 
Installing WP-CLI locally
Jason Yingling
 
Plugin development
Jason Yingling
 
Introducing CSS Grid
Jason Yingling
 
Customizing the WordPress Customizer
Jason Yingling
 
Battling Google PageSpeed Insights
Jason Yingling
 
Putting the Develop in Development
Jason Yingling
 
Getting to Know Underscores
Jason Yingling
 
Speeding Up WordPress sites
Jason Yingling
 
Creating Dynamic Sidebars & Widgets in WordPress
Jason Yingling
 
WordPress Template hierarchy
Jason Yingling
 
Design todevelop
Jason Yingling
 
Ithemes presentation
Jason Yingling
 
Building Flexible Sites with Advanced Custom Fields
Jason Yingling
 
Ad

Recently uploaded (20)

PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PPTX
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PPTX
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
PPT
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PPTX
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
PPT
introductio to computers by arthur janry
RamananMuthukrishnan
 
PDF
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PPTX
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
PPTX
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
PDF
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PPTX
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
PDF
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
introductio to computers by arthur janry
RamananMuthukrishnan
 
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 

Getting Started with Gutenberg Development

Editor's Notes

  • #5: The idea behind Gutenberg - tie the front end and the editor together. better user experience.
  • #6: Takes functionality that was previously done with shortcodes and makes it more visual within the editor. Drag and droppable. Save blocks to reuse across posts. Define blocks available to post types through templates.
  • #7: Better tie between visual on frontend and backend
  • #8: The tree of objects describes the blocks that compose a post in the editor view each item represents a block and the attributes within it that can be edited
  • #9: Once a block is saved in the editor it is saved into the database with an HTML comment In order to allow the saved content to be converted back into the “tree of objects” used by the editor the data is serialized into the HTML comment Were the “tree of objects” and output stored separately there would be the risk of data becoming out of sync
  • #11: Most blocks within Gutenberg will provide their own styles which can then be added to or overwritten by a theme Some features however require themes to opt-in for support as it is difficult for the block to supply styles to work with all themes as they can be handled multiple ways The wide and full image alignments are good examples Note: neither of these will work very well with sidebars
  • #12: Breaking out of a limited width parent. Pretty common to have a layout when the entire post content is wrapped in a fix width parent. Rather than recode there are ways to break outside the limits of the parent.
  • #13: The nicer way. No limit on the parent width, but you take all direct children and give them a max-width then overwrite the max-width as needed
  • #16: I tend to think of it this way: if I were to switch themes would losing the definition of a block effect content? It most likely would especially if there are any dynamic blocks. So blocks should be built in a plugin that can stay with a site through theme changes.
  • #21: Gutenberg introduces two new hooks for enqueuing scripts and styles for gutenber.
  • #22: The bulk of your block JS will be included in the enqueue_block_editor_assets Styles could be things like a focus state on an input in the editor. Whereas the front-end would only display the final value that was input.
  • #24: JS might be the JS needed for a slider to function. The bulk of your styles will be here.
  • #26: There is another way. Currently the method shown in the Gutenberg Handbook. Connected to the ‘init’ hook and passed as an argument Use ‘editor_script’, ’editor_style’, and ‘style’ I like the other hooks as it give more control and is similar to the current method of enqueueing scripts and styles
  • #29: Having an abstraction layer on top of react give WordPress protection against changes to React and leaves open doors for switching to other frameworks Basically if the need were to arise to switch off React an abstraction layer helps protect against the change effecting plugins and themes using the existing framework The wp.element library gives access to react’s createElement and render functions createElement Create and return a new React element tag name string (like div or span) or a React component In React you don’t typically need to call createElement directly if you’re writing in JSX. render Is the function used by React to render an element in the DOM
  • #31: BlockControls provides a toolbar of icons buttons to be used in the block editor. RichText provides an easy way to include a contenteditable interface in your block
  • #32: Allows for easily adding existing components to your own blocks allowing to keep the look and feel of block editing the same. Also gives a good head start to creating your own blocks.
  • #33: Allows you to easily make strings in your JavaScript translatable A .pot file can be generated using a custom Babel plugin to scan JS
  • #34: Gutenberg is built with modern JavaScript. What does that mean?
  • #35: ES6+ refers to any JS after ES6. JavaScript switched to a yearly release schedule with ES6 in 2015. ES Next refers to the next version of JS from the current release ES6 doesn’t replace ES5 it builds upon it Gutenberg can be fully built with ES5
  • #36: JSX is a syntax for writing HTML like markup within JavaScript Makes it much easier to read and write markup within your JavaScript Example shows a div, h2, and custom React component of RichText being written in JSX Note “className” is used as “class” is reserved in JS
  • #37: React is the framework used by Gutenberg for building user interfaces in JavaScript This is done by building components which are essentially custom HTML elements with their own functionality. Like the <RichText> element from the previous slide
  • #38: In order to use Modern JS in browser you’ll want a build tool that takes modern JS and JSX and outputs it into browser compatible JavaScript Babel is used to convert modern JS to browser compatible JS webpack is a build tool for watching and compiling files automatically
  • #39: The Block API consists of the functions WordPress exposes for adding functionality to the gutenberg editor
  • #40: importing styles is a pattern from React that is used in core development. It allows for scoping styles to blocks. define the functions you want to use from dependencies so you can call it independently.
  • #41: block name is the namespace/block-name discussed previously block configuration object is an object containing the attributes and functionality of your block the edit and save functions of the block configuration object define how the block works in the editor and frontend
  • #42: First let’s look at a handful of the available attributes
  • #46: Alias like an Image block using “Photo” Limited to 3 keywords per block
  • #47: Attributes are the data within the block. Attributes allow for extracting the value from a saved post for use in an editable block This example shows how you would be able to manipulate the src attribute from an img element.
  • #48: This is a simple (un-editable) example. This block would display a div with a paragraph in it in the editor. This example shows accessing the className by passing in props to the function
  • #49: The alternate save function of this simple block. This is what the block would output to the database a div wrapping a paragraph
  • #50: Some of the properties made available in the RichText component include: value: which is a string of what is entered in the input onChange: a callback handler fired when the value changes passing the new value placeholder: a string for placeholder text in the input multiline: a tag name that should be used when enter is pressed for example if set to li it would wrap each line in a li tagName the editable element. In the example we have a H2
  • #51: The edit function still shows a representation of the block in the editor’s context (this could be very different from the rendered version, it’s up to the block’s author) The save function just returns null because the rendering is performed server-side. The server-side rendering is a function taking the block attributes as an argument and returning the markup (quite similar to shortcodes)
  • #53: Ok so to recap. We need to <read list> … That’s a lot to handle and figure out
  • #54: Luckily there are several tools out there for speeding up this process create-guten-block is maybe the fastest setup I’ve come across Ot comes with JSX and ES6 syntax support Webpack build process for dev and production CSS prefixing To get started you’ll need Node.JS and npm installed Then you’ll globally install create-guten-block Then from the plugins folder of a local development site you can run “create-guten-block block-name” and it’ll spin up a full plugin ready for you to start building blocks with modern JS!