Blog: WordPress
Time-lapse tracer lights going down highway at night

Infinite Scroll With WordPress Custom Post Types

Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

UPDATE, Jan 1st 2015: Custom Post Type support looks like it was added in March of 2013 to the DIY plugin on GitHub, but does not exist in the Infinite Scroll plugin v2.62 in the WordPress.org free plugin directory.

The Infinite Scroll plugin was built for archive pages, loading more results when users scroll. Infinite Scroll does not load on single pages by default, and only loads on archives of regular posts, usually on a home page or blog page. The plugin authors did this to improve performance. But the WordPress plugin version doesn’t work with custom post types out-of-the-box.

Here’s how to make the WordPress plugin work with Custom Post Type archives.

Go to Plugins >> Edit >> Infinite Scroll and scroll all the way to the bottom of infinite-scroll/infinite-scroll.php, You’ll see this code block.


/** ORIGINAL CODE **/
/**
	 * Determines if the jQuery plugin and corresponding options should
	 * be output onto the page.
	 *
	 * @return bool
	 */
	function shouldLoadJavascript() {
		// Don't need to load the plugin on single pages
		if (is_single()) {
			return false;
		}

		return true;
	}
}

Change is_singular into is_single to make infinite scroll work on regular pages or with Custom Post Type archive pages.


/** NEW CODE BLOCK **/
/**
	 * Determines if the jQuery plugin and corresponding options should
	 * be output onto the page.
	 *
	 * @return bool
	 */
	function shouldLoadJavascript() {
		// Don't need to load the plugin on single pages
		if (is_single()) {
			return false;
		}

		return true;
	}
}

You could also set this to work on just specific pages, like so:


if (is_page('home')) {
			return true;
		}

		return true;
	}
}

Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

Join the Conversation

Your email address will be kept private. Required fields marked *.