Support

Account

Home Forums Gutenberg Conditionally Enqueueing Files if Page Contains Custom Block Reply To: Conditionally Enqueueing Files if Page Contains Custom Block

  • Sometimes adding scripts / libraries to Gutenberg Editor (backend) cause serious problems. In case someone else have problems you can simply use if(! is_admin()) inside enqueue_assets, like so:

    ` ‘enqueue_assets’ => function () {
    // Load assets only on frontend – the libs cause unwanted sideeffects in gutenberg
    if(! is_admin()){
    wp_enqueue_script(‘filtrify’, get_stylesheet_directory_uri() . ‘/libraries/stuff/js/foo.min.js’, array(‘jquery’), null, true);
    }
    },