I'm using the Underscores theme which comes with the following (very) handy code in inc/jetpack.php

add_theme_support( 'infinite-scroll', array(
    'container' => 'main',
    'render'    => 'infinite_scroll_render',
    'footer'    => 'page',
    'wrapper'   => false
) );

function infinite_scroll_render() {
  while ( have_posts() ) {
    if ( is_search() ) :
        get_template_part( 'template-parts/content', 'search' );
    else :
        get_template_part( 'template-parts/content-', get_post_type() );

I can't figure out the best way to edit either of these functions to ignore a particular post type. I can pass if( is_post_type_archive('service') ) but if I just 'return' then the rest of the page doesn't render - it just stops there.

How can I specify which post types Infinite Scroll fires on?


Stand down! I got it with 'pre_get_posts':

add_action( 'pre_get_posts', 'pre_service_archive' );
function pre_service_archive() {
    if( is_post_type_archive( 'service' ) ) remove_theme_support( 'infinite-scroll' );
| improve this answer | |
  • This saved me! i hope it works! – Maxwell s.c Mar 2 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.