<?php
// Disable FacetWP's query variables in the URL, except for Pager facets.
// To entirely disable FacetWP's query variables, see:
// https://facetwp.com/help-center/developers/the-facetwp-url/#disable-facetwps-query-string
add_action( 'facetwp_scripts', function() {
  ?>
  <script>
    document.addEventListener('facetwp-refresh', function() {
        FWP.buildQueryString = function() {
          var fwp_vars = Object.assign({});
          // Add pagination to the URL hash
          if (1 < FWP.paged) {
            fwp_vars['paged'] = FWP.paged;
          }
          fwp_vars = FWP.helper.serialize(fwp_vars, FWP_JSON.prefix);
          return fwp_vars;
        }
    });
  </script>
  <?php
}, 100 );