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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.