Skip to content

Instantly share code, notes, and snippets.

@djrmom
Created May 1, 2018 16:43
Show Gist options
  • Select an option

  • Save djrmom/4e41b3da62b669712bfc7a22333d4899 to your computer and use it in GitHub Desktop.

Select an option

Save djrmom/4e41b3da62b669712bfc7a22333d4899 to your computer and use it in GitHub Desktop.
facetwp conditional scroll to top
<?php
/** adds script to header with a conditional check to not scroll to top
** when the load more button has been clicked
**/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if ( FWP.is_load_more == true ) {
FWP.enable_scroll = false;
} else {
FWP.enable_scroll = true;
}
});
$(document).on('facetwp-loaded', function() {
if ( FWP.enable_scroll == true ) {
$('html, body').animate({ scrollTop: 0 }, 500);
}
});
})(jQuery);
</script>
<?php } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment