Skip to content

Instantly share code, notes, and snippets.

@zgordon
Last active December 8, 2017 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zgordon/fd28409d08414f7815044c6e0fc8114e to your computer and use it in GitHub Desktop.
Save zgordon/fd28409d08414f7815044c6e0fc8114e to your computer and use it in GitHub Desktop.
How to register a new Gutenberg visual editor block in JavaScript
// Import __ from i18n internationalization library
const { __ } = wp.i18n;
// Import registerBlockType() from block building libary
const { registerBlockType } = wp.blocks;
// Import the element creator function (React abstraction layer)
const el = wp.element.createElement;
/**
* Register Block using default icon options.
*
* @param {String} name Block name, namespaced
* @param {Object} settings Block settings
* @return {?WPBlock} Return the block or 'undefined'
*/
registerBlockType('js4wpgb/static-content', {
title: __('Custom Block', 'JS4WPGB'),
// Icon for the block
// Choose from here by default https://developer.wordpress.org/resource/dashicons/
icon: 'admin-settings',
category: 'common',
edit( props ) {
return el('p', {}, 'Hello world!');
},
save( props ) {
return el('p', {}, 'Hello world!');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment