Skip to content

Instantly share code, notes, and snippets.

@ravewebdev
Created July 15, 2020 15:57
Show Gist options
  • Save ravewebdev/6c97ae211c43c3c3d984c19a69adf5eb to your computer and use it in GitHub Desktop.
Save ravewebdev/6c97ae211c43c3c3d984c19a69adf5eb to your computer and use it in GitHub Desktop.
1.2. Frontend Rendering
<?php
register_block_type( 'rave/initiative-tracker', array(
'editor_script' => 'initiative-tracker-editor-script',
'editor_style' => 'initiative-tracker-editor-style',
'style' => 'initiative-tracker-style',
'render_callback' => __NAMESPACE__ . '\render_block',
) );
function render_block( array $attributes ) : string {
$id = $attributes['id'];
$class = 'wp-block-rave-initiative-tracker';
ob_start();
?>
<div
class="<?php echo esc_attr( $class ); ?>"
data-id="<?php echo esc_attr( $id ); ?>"
data-post_id="<?php echo esc_attr( get_the_ID() ); ?>"
>
<!-- Your actual block content here... -->
</div>
<?php
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment