Conditionally disable Jetpack’s Infinite Scroll

So you implemented Jetpack’s Infinite Scroll feature in your theme, but you don’t want it in a particular page, say a category archive page. Here’s the code you need to add to your theme’s functions.php file:

/**
 * Disable Jetpack's Infinite Scroll Conditionally
 *
 */
function _kucrut_disable_jetpack_infinite_scroll_conditionally() {
	if ( true === my_conditionals() ) {
		remove_theme_support( 'infinite-scroll' );
	}
}
add_action( 'template_redirect', '_kucrut_disable_jetpack_infinite_scroll_conditionally', 9 );

Just remember to change my_conditionals() with your actual conditionals and to never add the action callback after priority 9, otherwise it will be too late 😉

Standard

Comments

  1. One could also use the infinite_scroll_archive_supported filter (see source) which is used for checking if the infinite scroll should be enabled or not:

    add_filter( 'infinite_scroll_archive_supported', function( $supported ) {
    	// Disable on category archives, for example
    	if ( is_category() ) {
    		return false;
    	}
    
    	return $supported;
    });
  2. Jamie says:

    After a couple of hours of of Google-Fu, I landed on this post and it solved my problem. The documentation for Infinite Scroll is lacking to say the least. Thank you for sharing this!