Support

Account

Home Forums Gutenberg Display block differently in editor and front-end

Solved

Display block differently in editor and front-end

  • I’m using ACF’s functionality to create a custom block. I’ve got everything working great using a template file.

    The block content has an image wrapped in an A tag with an href. However, in the editor I would like to omit the A tag so that the user does not accidentally click on it in the block editor and get sent to another URL.

    In short, is there some code/conditional I can put in my block render template so that my block renders one way in the block editor and a slightly different way in the front-end? A function of some kind? Or perhaps something in the $block object I can conditionalize against?

    Thank you!

  • I think I may have found my own answer:

    Is it $is_preview which is true during AJAX preview?

  • It is!

    In my template file $is_preview is true if the block is being rendered in the block editor and false if it is being rendered on the front-end.

    Yay!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.