PHP is_embed error showing up

The error itself is not because debug mode, it seems that the hook you’re using is being called before the $wp_query is set.

what you can do is put inside your function

function your_error_function(){
        global $wp_query;
        if(! isset( $wp_query )){
          return 
        }
    ...rest of my code
}

or change the hook you’re using to another that is called later, something like ‘loop_start’ should do.

error code: 523