This file contains 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
function custom_allowed_block_types($original_blocks) | |
{ | |
// Alter the allowed block types: | |
// - Only list block types you want enabled | |
// - Each custom block you develop needs to be listed below | |
// https://rudrastyh.com/gutenberg/remove-default-blocks.html | |
return [ | |
'core/block', // --> Keep reusable blocks <-- | |
// 1. Common blocks category | |
'core/heading', |
This file contains 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 custom_colours(): void | |
{ | |
// Set default options for background and text colours | |
add_theme_support( | |
'editor-color-palette', | |
[ | |
[ | |
'name' => 'White', | |
'slug' => 'white', |
This file contains 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 | |
$html = ''; | |
$html .= '<div class="row">'; | |
foreach ( $block['innerBlocks'] as $column ) { | |
// $column = "core/column" | |
$html .= '<div class="col-md" style="...">'; | |
foreach ( $column['innerBlocks'] as $inner_block ) { | |
// Renders <p>A paragraph inside a group</p> and ... | |
$html .= render_block( $inner_block ); | |
} |
This file contains 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 | |
if ( | |
$block['blockName'] === 'core/group' && | |
!is_admin() && | |
!wp_is_json_request() | |
) { | |
// Detect the block you want and only render in the front-end | |
} |
This file contains 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 | |
// Extract the anchor of a core/group, core/heading and | |
// exclude anchor attributes from inner blocks. | |
preg_match('/id="(.+?)"/', $block['innerHTML'], $id_matches); |
This file contains 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 custom_render_block_core_group ( | |
string $block_content, | |
array $block | |
): string | |
{ | |
if ( | |
$block['blockName'] === 'core/group' && | |
!is_admin() && |