• This block is really cool, and does appear to be very lightweight. My only concern is that the scripts are loaded on every page. The scripts should only be loaded on pages where the block is used. Maybe because I’m not using an FSE/block theme? For now, I’ll have to dequeue or use something else. Thanks for building this plugin either way, it’s very useful ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter JiveDig

    (@jivedig)

    FWIW, here is the code I’m currently using to remove the scripts.

    /**
    * Remove scripts and styles.
    *
    * @return void
    */
    add_action( 'wp_print_styles', function() {
    $scripts = [];
    $styles = [];

    // Single posts/pages/cpts.
    if ( is_singular() ) {
    $post = get_post();

    if ( ! has_block( 'icgb/image-compare', $post ) ) {
    $scripts[] = 'icgb__image-compare-viewer-js';
    $scripts[] = 'icgb__plugin-js';
    }
    }

    if ( $scripts ) {
    foreach ( $scripts as $handle ) {
    wp_dequeue_script( $handle );
    }
    }

    if ( $styles ) {
    foreach ( $styles as $handle ) {
    wp_dequeue_style( $handle );
    }
    }

    // global $wp_scripts, $wp_styles;
    // printf( '<pre>%s</pre>', print_r( $wp_scripts->queue, true ) );
    // printf( '<pre>%s</pre>', print_r( $wp_styles->queue, true ) );

    }, 9999 );
    Plugin Author Binsaifullah

    (@binsaifullah)

    Hi,

    thanks for your suggestion. I will fix the matter in the next update. thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.