jenny-r
5/2/2018 - 5:01 PM

facetwp scroll to top on wp_head hook

facetwp scroll to top on wp_head hook

<?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-loaded', function() {
              if (FWP.loaded) {
                  $('html, body').animate({
                      scrollTop: $('.facetwp-template').offset().top
                  }, 500);
              }
          });
        })(jQuery);
    </script>

<?php } );