facetwp-loaded Event
Overview
This JS event gets triggered when FacetWP finishes refreshing. It’s triggered after a user interacts with a facet or pagination control. This event is useful for modifying facet output after being rendered.
Usage
Example 1: scroll to the top of the page after an ajax refresh:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_action( 'wp_footer', function() { ?> <script> document.addEventListener('facetwp-loaded', function() { window.scrollTo({ top: 0, behavior: 'smooth' }); }); </script> <?php }, 100 );
Example 2: reinitialize Jetpack Lazy Load after an ajax refresh:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_action( 'wp_footer', function() { ?> <script> document.addEventListener('facetwp-loaded', function() { fUtil('body').trigger('jetpack-lazy-images-load'); }); </script> <?php }, 100 );