1. Home
  2. Help Center
  3. WooCommerce
  4. Customization
  5. Collapse WCAPF filter widgets on page load

This mod makes the widget collapsed by default. But there will be always a delay, the widgets load open and then close automatically after a second.

Add this PHP snippet to functionswp-content/themes/goya-child/functions.php

<?php 
add_action('wp_footer','woocommerce_js');
function woocommerce_js() { ?>
<script>
jQuery(document).ready(function($) {
 setTimeout(function(){
  var $filterTitle = $('#side-filters').find('.widgettitle');
  $filterTitle.each(function() {
   if(!$(this).hasClass('active')){
    $(this).trigger('click').addClass('auto-open');
   }
  });
 }, 10);
});
</script>
<?php }Code language: HTML, XML (xml)

And this CSS snippet to Appearance > Customize > Additional CSS

#side-filters .widgettitle {
 margin-bottom: 0;
}
#side-filters .widgettitle:not(.auto-open) + .wcapf-layered-nav {
 height: 0; opacity: 0;
}Code language: CSS (css)

Was this article helpful?

Related Articles