My goal is to use the Gutenberg Block for the backend editor to collect the data but output it only with php.

I added a server-side-render component to my block. Now I can edit attributes in the Gutenberg Editor and output them on the server side with php. But the output is renderer in the editor as well. I don't need that because it displays everything twice. How do I hide the server side render output in editor?

Do I prevent the output in php with something like "if is_frontend() {return $output}" or is there an attribute for server side render to keep it off Gutenberg?

1 Answer 1


This can be down in the php render_function. Check if it is an API REST request:

function create_block() {
    register_block_type( __DIR__ ,[
        'render_callback' => 'render_php'
    ] );

function render_php(){

    if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
        return "<p>Backend says hello from php</p>";
    } else {
        return "<p>Frontend says hello from php</p>";


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.