Skip to content

Instantly share code, notes, and snippets.

@knuch
Created July 24, 2019 08:32
Show Gist options
  • Select an option

  • Save knuch/ffdc55c41c33d0a22430099af03d6f10 to your computer and use it in GitHub Desktop.

Select an option

Save knuch/ffdc55c41c33d0a22430099af03d6f10 to your computer and use it in GitHub Desktop.

Revisions

  1. knuch revised this gist Jul 24, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    // https://developer.wordpress.org/reference/hooks/render_block/

    add_filter( 'render_block', 'foo_core_gallery_filter', 10, 3);
  2. knuch created this gist Jul 24, 2019.
    22 changes: 22 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    // https://developer.wordpress.org/reference/hooks/render_block/

    add_filter( 'render_block', 'foo_core_gallery_filter', 10, 3);

    function foo_core_gallery_filter( $block_content, $block ) {

    // use blockName to only affect the desired block
    if( "core/calendar" !== $block['blockName'] ) {
    return $block_content;
    }

    // $block_content contains all the data passed to the block callback function
    // $block contains the serialized block markup

    // Here you have all content over the block. Either wrap it in your container or totally replace the content
    $output = '<h2 class="foo-gallery">';
    $output .= 'GALLERY';
    $output .= '</h2>';

    // return the new content of the block
    return $output;
    }