Skip to content

Instantly share code, notes, and snippets.

View bastiaandewaele's full-sized avatar

Bastiaan Dewaele bastiaandewaele

View GitHub Profile
@bastiaandewaele
bastiaandewaele / Gutenberg - Disable blocks method 1.php
Created August 13, 2020 20:16
Gutenberg - Disable blocks method 1
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',
@bastiaandewaele
bastiaandewaele / Gutenberg - editor-color-palette.php
Created August 13, 2020 19:58
Gutenberg - editor-color-palette
<?php
function custom_colours(): void
{
// Set default options for background and text colours
add_theme_support(
'editor-color-palette',
[
[
'name' => 'White',
'slug' => 'white',
@bastiaandewaele
bastiaandewaele / Customize Existing Gutenberg blocks - core-columns.php
Created August 8, 2020 07:20
Customize Existing Gutenberg blocks - core/columns.php
<?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 );
}
@bastiaandewaele
bastiaandewaele / Customize Existing Gutenberg blocks - the new way.php
Last active August 16, 2020 19:44
Customize Existing Gutenberg blocks - the new way
<?php
if (
$block['blockName'] === 'core/group' &&
!is_admin() &&
!wp_is_json_request()
) {
// Detect the block you want and only render in the front-end
}
@bastiaandewaele
bastiaandewaele / Customize Existing Gutenberg blocks - Variable $block.php
Created August 8, 2020 07:13
Customize Existing Gutenberg blocks - Variable $block
<?php
// Extract the anchor of a core/group, core/heading and
// exclude anchor attributes from inner blocks.
preg_match('/id="(.+?)"/', $block['innerHTML'], $id_matches);
@bastiaandewaele
bastiaandewaele / gist:d2af691b814ce060fa6239ed774f06d5
Last active August 16, 2020 19:42
Customize Existing Gutenberg blocks - the new way
<?php
function custom_render_block_core_group (
string $block_content,
array $block
): string
{
if (
$block['blockName'] === 'core/group' &&
!is_admin() &&