// proof-of-concept to extract all WordPress Gutenberg's blocks as array // author: Frank Goossens (Futta) // source: https://blog.futtta.be/2018/01/25/how-to-extract-blocks-from-gutenberg/ add_action('the_content','gutenprint',10,1); function gutenprint($html) { // check if we need to and can load the Gutenberg PEG parser if ( !class_exists("Gutenberg_PEG_Parser") && file_exists(WP_PLUGIN_DIR."/gutenberg/lib/load.php") ) { include_once(WP_PLUGIN_DIR."/gutenberg/lib/load.php"); } if ( class_exists("Gutenberg_PEG_Parser") && is_single() ) { // do the actual parsing $parser = new Gutenberg_PEG_Parser; $result = $parser->parse( _gutenberg_utf8_split( $html ) ); // we need to see the HTML, not have it rendered, so applying htmlentities array_walk_recursive($result, function (&$result) { $result = htmlentities($result); } ); // and dump the array to the screen echo "

Gutenprinter reads:

";
      var_dump($result);
      echo "
"; } else { echo "Not able to load Gutenberg parser, are you sure you have Gutenberg installed?"; } // remove filter to avoid double output remove_filter('the_content','gutenprint'); // and return the HTML return $html; }