This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mytheme_setup_theme_supported_features() { | |
add_theme_support( 'editor-color-palette', | |
'#556270', | |
'#4ECDC4', | |
'#C7F464', | |
'#FF6B6B', | |
'#C44D58', | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get helper functions from global scope | |
const { registerBlockType } = window.wp.blocks; | |
const { __ } = window.wp.i18n; | |
// Use registerBlockType to create a custom block | |
registerBlockType( | |
'example-plugin/example-custom-block', | |
{ | |
// Localize title using wp.i18n.__() | |
title: __( 'Block Title' ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get registerBlockType() from wp.blocks in the global scope | |
const { registerBlockType } = window.wp.blocks; | |
// Two parameters, name and settings | |
registerBlockType( 'example-plugin/example-custom-block', {} ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get registerBlockType() from wp.blocks in the global scope | |
const { registerBlockType } = window.wp.blocks; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enqueue block editor CSS | |
*/ | |
function jsforwpblocks_editor_scripts() { | |
// Make paths variables so we don't write em twice ;) | |
$editorStylePath = '/assets/css/blocks.editor.css'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enqueue block editor JavaScript and CSS | |
*/ | |
function jsforwpblocks_editor_scripts() { | |
// Make paths variables so we don't write em twice ;) | |
$blockPath = '/assets/js/blocks.js'; | |
$editorStylePath = '/assets/css/blocks.editor.css'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require( 'path' ); | |
// const BrowserSyncPlugin = require( 'browser-sync-webpack-plugin' ); | |
const webpack = require( 'webpack' ); | |
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' ); | |
// Set different CSS extraction for editor only and common block styles | |
const blocksCSSPlugin = new ExtractTextPlugin( { | |
filename: '../css/blocks.style.css', | |
} ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/theme-root | |
/blocks | |
/block-name | |
editor.css // Option for editor only styles | |
index.js // Main block JS file | |
index.php // Enqueues the block JS and CSS | |
style.css // Frontend and editor styles | |
/another-block-name | |
editor.css | |
index.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enqueue block-name main JavaScript file for the editor | |
*/ | |
function js4wp_block_name_enqueue_scripts() { | |
// Make path a variable so we don't write it twice ;) | |
$blockPath = '/blocks/block-name/index.js'; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Require a block | |
require_once( get_template_directory() . '/blocks/block-name/index.php'); | |
// Require another block | |
require_once( get_template_directory() . '/blocks/another-block-name/index.php'); |