Home Forums Gutenberg Different render_callback while editing post


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?

    • philby

    • March 30, 2019 at 4:10 am

    Still haven’t had much luck with this so far.
    Conditionals using (id_admin()) or `$current_screen = get_current_screen();
    if ( method_exists( $current_screen, ‘is_block_editor’ ) && $current_screen->is_block_editor() ) {` just made the block editor stop being able to save the page.

  • You can also give the element a css rule in your custom editor css file:
    .yourelement { pointer-events: none; }
    Then the element is not clickable.

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