Skip to content

Instantly share code, notes, and snippets.

@eudesgit
Last active June 14, 2018 17:32
Show Gist options
  • Save eudesgit/5bac0d55e2c3f42f08a529010c42e22d to your computer and use it in GitHub Desktop.
Save eudesgit/5bac0d55e2c3f42f08a529010c42e22d to your computer and use it in GitHub Desktop.
A render function for a WordPress Gutenberg block in PHP
<?php
/**
* CALLBACK
*
* Render callback for the dynamic block.
*
* Instead of rendering from the block's save(), this callback will render the front-end
*
* @since 1.0.0
* @param $att Attributes from the JS block
* @return string Rendered HTML
*/
public function block_dynamic_render_cb ( $att ) {
// Coming from RichText, each line is an array's element
$sum = $att['number1'][0] + $att['number2'][0];
$html = "<h1>$sum</h1>";
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment