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
// 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
// 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 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
<?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
<?php | |
add_theme_support( 'gutenberg', [ | |
'wide-images' => true, | |
'colors' => [ | |
'#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
const { | |
Button, | |
Dashicon, | |
Tooltip, | |
} = wp.components; | |
// Wrap the Tooltip component around whatever you want to activate the tooltip on hover | |
<Tooltip | |
text={ __( 'Add Tooltip Text Here' ) } | |
> |
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
// Load the theme stylesheets | |
function theme_styles() | |
{ | |
// Example of loading a jQuery slideshow plugin just on the homepage | |
wp_register_style( 'flexslider', get_template_directory_uri() . '/css/flexslider.css' ); | |
// Load all of the styles that need to appear on all pages | |
wp_enqueue_style( 'main', get_template_directory_uri() . '/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
<?php | |
function mytheme_block_templates( $args, $post_type ) { | |
// Only add template to 'post' post type | |
// Change for your post type: eg 'page', 'event', 'product' | |
if ( 'post' == $post_type ) { | |
// Optionally lock templates from further changes | |
// Change to 'insert' to allow adding other blocks, but lock defined 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
// Deconstruct just the __ function from wp.i18n global object | |
const { __ } = wp.i18n; | |
// Just pass in the text to make it available for translation | |
__( 'This text can be translated', 'textdomain' ); | |
// If used within JSX, you may need to do something like this | |
{ __( 'Translate my JSX string', 'textdomain' ) } |