Gutenberg running code only available in front end within shortcode


In a pre-Gutenberg site, I have a shortcode with roughly the following structure:

function generate_new_member_form() {
    ob_start(); ?>
   // a form
   // to generate this form there is some code that uses objects or functions 
   // only available in the front end
  <?php return ob_get_clean();

add_shortcode('new-member-form', 'generate_new_member_form');

For whatever it’s worth, the code has to do with Woocommerce checkout fields, and I get fatal errors when I try to edit a page that has the shortcode [new_member_form] such as “Call to a member function get() on null”. But I don’t think the problem has to do with Woocommerce

Is there a way to prevent Gutenberg from trying to run any of this code in the backend? I would like to be able to edit the page and see just [new_member_form] with no attempt to display the shortcode.

, adelval 4 years 2019-11-29T23:16:52-05:00 0 Answers 75 views 0

Leave an answer