function custom_infinite_scroll_js() {
if ( ! is_singular() ) { ?>
<script>
var infinite_scroll = {
loading: {
img: "<?php echo get_template_directory_uri(); ?>/images/ajax-loader.gif",
msgText: "<?php _e( 'Loading the next set of posts...', 'blewspaper' ); ?>",
finishedMsg: "<?php _e( 'All posts loaded.', 'blewspaper' ); ?>"
},
"nextSelector":"#nav-below .nav-previous a",
"navSelector":"#nav-below",
"itemSelector":"article",
"contentSelector":"#content"
};
jQuery( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll );
</script>
<?php
}
}
add_action( 'wp_footer', 'custom_infinite_scroll_js', 100 );
Error in console →
Uncaught TypeError: jQuery(...).infinitescroll is not a function
at (index):571
when I clicked the line it shows is this one →
jQuery( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll );
Please help me to fix this.
Additional information:
This is relying on this:
https://unpkg.com/infinite-scroll@3/dist/infinite-scroll.pkgd.min.js
which is included in wordpress →
function custom_theme_js() {
wp_register_script(
'infinite_scroll',
get_template_directory_uri() . '/js/infinite-scroll.pkgd.min.js',
array('jquery'),
null,
true
);
if ( ! is_singular() ) {
wp_enqueue_script( 'infinite_scroll' );
}
}
add_action( 'wp_enqueue_scripts', 'custom_theme_js' );