Skip to content

Instantly share code, notes, and snippets.

@khromov
Created September 17, 2022 21:37
Show Gist options
  • Save khromov/b0f3838aaf663896e0ae94f0db111b92 to your computer and use it in GitHub Desktop.
Save khromov/b0f3838aaf663896e0ae94f0db111b92 to your computer and use it in GitHub Desktop.
Gutenberg block templates with Advanced Custom Fields
<?php
/*
Plugin Name: Plugin
Version: 1.0
*/
add_action('acf/init', function() {
// Check function exists.
if( function_exists('acf_register_block_type') ) {
// register a testimonial block.
acf_register_block_type([
'name' => 'rating',
'title' => __('Rating'),
'description' => __(''),
'render_template' => plugin_dir_path( __FILE__ ) . 'template-rating.php',
'category' => 'widgets',
'icon' => 'admin-comments',
'keywords' => ['rating', 'rank', 'grade'],
]);
}
});
<?php
ob_start();
?>
<!-- wp:group {"style":{"spacing":{"padding":{"top":"0px","right":"0px","bottom":"0px","left":"0px"}}},"backgroundColor":"tertiary","layout":{"inherit":false}} -->
<div class="wp-block-group has-tertiary-background-color has-background" style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
<!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"left"}} -->
<div class="wp-block-group">
<!-- wp:group {"style":{"border":{"radius":"0px"}},"layout":{"wideSize":"","contentSize":""}} -->
<div class="wp-block-group" style="border-radius:0px">
<!-- wp:heading {"textAlign":"right","level":6,"backgroundColor":"vivid-red","textColor":"background","fontSize":"tiny"} -->
<h6 class="has-text-align-right has-background-color has-vivid-red-background-color has-text-color has-background has-tiny-font-size">A</h6>
<!-- /wp:heading -->
</div>
<!-- /wp:group -->
<!-- wp:paragraph {"align":"left","fontSize":"small"} -->
<p class="has-text-align-left has-small-font-size">Rating</p>
<!-- /wp:paragraph -->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
<?php
echo do_blocks(ob_get_clean());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment