Home › Forums › Gutenberg › Register block preview image with acf_register_block_type? › Reply To: Register block preview image with acf_register_block_type?
I found a workaround since the above solution wasn’t working for me, and is kind of a pain if using
get_fields(). Turns out you don’t need to add any custom data to the preview. Turns out when fetching the preview, WordPress includes the fact that it is a preview within the $_POST params.
So you can just set up the example like this when registering the block
'example' => [ 'attributes' => [ 'mode' => 'preview', 'data' => , ] ],
Then when rendering the content check if it is a preview like this
if( ! empty( $_POST['query']['preview'] ) : /* Render screenshot for example */ else : /* Render HTML for block */ endif;
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.