• Resolved Will Stocks

    (@willstockstech)


    Hi guys,
    Just wondering – why can’t I dequeue the following scripts/styles for comment-likes as follows:

    if( ! is_single() ) {
    	//Jetpack
    	wp_dequeue_style('jetpack_likes');
    	wp_dequeue_script('postmessage');
    	wp_dequeue_script('jetpack_resize');
    	wp_dequeue_script('jetpack_likes_queuehandler');
    }

    I’ve even tried:
    apply_filters ( 'wpl_is_index_disabled', TRUE );
    but still no luck 🙁

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Velda

    (@supernovia)

    Hi, can you send a link to the affected site?

    Also, while this individual as dequeuing something else, the tips in this thread may help:
    https://wordpress.org/support/topic/proper-way-to-dequeue-jetpack-social-menu-style/

    Thread Starter Will Stocks

    (@willstockstech)

    Thanks @supernovia – I’ll give add_filter( 'jetpack_implode_frontend_css', '__return_false' ); a go to see if that makes any difference!

    So if I add the following:

    remove_jetpack_commentlikes_from_nonsingle() {
    	if( ! is_single() ) {
    		//Jetpack
    		add_filter( 'jetpack_implode_frontend_css', '__return_false' );
    		apply_filters ( 'wpl_is_index_disabled', '__return_true');
    		wp_dequeue_style('jetpack_likes');
    		wp_dequeue_script('postmessage');
    		wp_dequeue_script('jetpack_resize');
    		wp_dequeue_script('jetpack_likes_queuehandler');
    	}
    }
    add_action( 'wp_enqueue_scripts', 'remove_jetpack_commentlikes_from_nonsingle' );

    In theory this would do the trick?

    Hi @willstockstech,

    Correct — please try adding:

    add_filter( 'jetpack_implode_frontend_css', '__return_false' );

    In addition to the dequeue code you were already using. The code I pasted above should mean the CSS specific to those features isn’t enqueued in the concatenated jetpack.css file.

    Thread Starter Will Stocks

    (@willstockstech)

    Woohoooo – all sorted! 🙂

    Thanks guys!

    I’ve gone with:

    add_filter( 'jetpack_implode_frontend_css', '__return_false' );
    function remove_jetpack_commentlikes_from_nonsingle() {
    	if( ! is_single() ) {
    		//Jetpack
    		apply_filters ( 'wpl_is_index_disabled', '__return_true');
    		wp_dequeue_style('jetpack_likes');
    		wp_dequeue_script('postmessage');
    		wp_dequeue_script('jetpack_resize');
    		wp_dequeue_script('jetpack_likes_queuehandler');
    	}
    }
    add_action( 'wp_enqueue_scripts', 'remove_jetpack_commentlikes_from_nonsingle' );
    add_action('wp_print_styles', 'remove_jetpack_commentlikes_from_nonsingle' );

    Which has done the trick – the only thing I’m not 100% sure about is whether I should be using wp_print_styles or wp_enqueue_scripts?

    Plugin Support Velda

    (@supernovia)

    You’ll likely want to use wp_enqueue_scripts. Let us know if you need more help!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Dequeue styles/scripts unless is_single’ is closed to new replies.