Last active
September 27, 2020 14:18
-
-
Save johnrom/4eee77fbc677f2a15779bf5720c34f4f to your computer and use it in GitHub Desktop.
Dream Post Rendering
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
<!--<WPCONTENT>{ | |
"blocks": [ | |
{ | |
"type": "header", | |
"class": "header-rendered", | |
"content": "%%WPC[0]%%", | |
"block_type": "h2" | |
}, | |
{ | |
"type": "wrapper", | |
"class": "content-rendered", | |
"blocks": [ | |
{ | |
"type": "image", | |
"caption": "%%WPC[1][0]%%", | |
"url": "http://example.com/my-image.jpg" | |
} | |
] | |
} | |
] | |
}</WPCONTENT>--> | |
<!-- #WPRAW --> | |
<div><div class="header-rendered"><h2><!-- #WPC[0] -->I entered this content into this block type<!-- #/WPC[0] --></h2></div><div class="content-rendered"><div><figure><img src="http://example.com/my-image.jpg"><figcaption><!-- #WPC[1][0] -->A picture is worth a thousand words<!-- #/WPC[1][0] --></figcaption></figure></div></div></div> | |
<!-- Example usage | |
// add_filter('new_filter_before_wp_content', function( $wp_content ) { | |
// $blocks = $wp->parse_content( $wp_content ); // get json from <WPCONTENT/> with "content" attributes parsed with #WPC[] comment values | |
// | |
// if ( ! is_array( $blocks ) { | |
// $blocks = array( $blocks ); | |
// } | |
// | |
// foreach( $json['blocks'] as $block ) { | |
// | |
// if $wp->can_render( $block ) { | |
// $blocks[] = $wp->render( $block ); | |
// } else { | |
// $blocks[] = $wp->use_raw( $block ); | |
// } | |
// } | |
// | |
// array_map( 'echo', $blocks ); | |
// } | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment