Last active
July 20, 2021 15:32
-
-
Save djrmom/fe96ec2a3eba6bcaec6e1f3ef9cdf390 to your computer and use it in GitHub Desktop.
facetwp show/hide labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_footer', function() { | |
?> | |
<script> | |
(function($) { | |
if ('object' !== typeof FWP) { | |
return; | |
} | |
$(function() { | |
FWP.hooks.addAction('facetwp/loaded', function() { | |
/* run code here after facetwp loaded, 100 below can be modified to set priority order */ | |
$('.facetwp-facet').each(function() { | |
var facet_name = $(this).attr('data-name'); | |
var facet_label = FWP.settings.labels[facet_name]; | |
if ( 'undefined' !== typeof FWP.settings.num_choices[facet_name] && FWP.settings.num_choices[facet_name] > 0 && $('.facet-label[data-for="' + facet_name + '"]').length < 1 ) { | |
$(this).before('<h3 class="facet-label" data-for="' + facet_name + '">' + facet_label + '</h3>'); | |
} else if ( 'undefined' !== typeof FWP.settings.num_choices[facet_name] && !FWP.settings.num_choices[facet_name] > 0 ) { | |
$('.facet-label[data-for="' + facet_name + '"]').remove(); | |
} | |
}); | |
}, 100 ); | |
}); | |
})(jQuery); | |
</script> | |
<?php | |
}, 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, please check https://facetwp.com/documentation/support/ for help with Facet. Thanks.