Support

Account

Home Forums Gutenberg Different render_callback while editing post

Helping

Different render_callback while editing post

    • philby

    • November 16, 2018 at 11:26 pm

    My project involves pages with a lot of post object relational fields, where a posts post_thumbnail and title are displayed in a grid.

    While previewing the page or generally on the frontend, the entire block element will be linked to the post.

    While editing in Gutenberg with preview = true, I’d like to not render the a href around the div that makes up the block, since it makes selecting any block almost impossible.

    I’ve tried adding

    $screen = get_current_screen();
    if ( $screen->parent_base != 'edit' ) {

    but Gutenberg doesn’t like it and stops saving the post with
    Failed to load resource: the server responded with a status of 500 () error.

    Is there an official way to have a different render_callback depending on whether we’re editing or previewing/viewing a post?

  • I used if(is_admin()) check in the block-render.php page to split code into frontend / backend output.

    Is there a better option?

Viewing 2 posts - 1 through 2 (of 2 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.