Skip to content

Instantly share code, notes, and snippets.

@devinsays devinsays/enqueue.php
Last active Jan 28, 2018

Embed
What would you like to do?
Infinite Scroll
<?php
/**
* Load javascripts used by the theme
*/
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' );
/**
* Infinite Scroll
*/
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...', 'custom' ); ?>",
finishedMsg: "<?php _e( 'All posts loaded.', 'custom' ); ?>"
},
"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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.