Skip to content

Instantly share code, notes, and snippets.

@kingkool68
Created October 18, 2023 20:43
Show Gist options
  • Select an option

  • Save kingkool68/4fc77a809f608b49a25c2b92b871aa8e to your computer and use it in GitHub Desktop.

Select an option

Save kingkool68/4fc77a809f608b49a25c2b92b871aa8e to your computer and use it in GitHub Desktop.

Revisions

  1. kingkool68 created this gist Oct 18, 2023.
    17 changes: 17 additions & 0 deletions parse_andserialize_blocks.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?php
    function rh_filter_the_content( $the_content = '' ) {
    $blocks = parse_blocks( $the_content );
    $new_block = array(
    'blockName' => 'core/paragraph',
    'attrs' => array(),
    'innerBlocks' => array(),
    'innerHTML' => '<p>Hello World</p>',
    'innerContent' => array(
    '<p>Hello World</p>',
    ),
    );
    $blocks[] = $new_block;

    return serialize_blocks( $blocks );
    }
    add_filter( 'the_content', 'rh_filter_the_content', 5 );