Skip to content

Instantly share code, notes, and snippets.

@alvics
Last active March 28, 2019 00:47
Show Gist options
  • Save alvics/5a6e8e5ef27f533870a7901c7fd41bc7 to your computer and use it in GitHub Desktop.
Save alvics/5a6e8e5ef27f533870a7901c7fd41bc7 to your computer and use it in GitHub Desktop.
facetwp - Show h3 label and hide facet and h3 label when empty
// Hide Facet & H3 Label When Empty
function fwp_add_facet_labels() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.facetwp-facet').each(function() {
var facet_name = $(this).attr('data-name');
var facet_label = FWP.settings.labels[facet_name];
if ($('.facet-label[data-for="' + facet_name + '"]').length < 1 && $(this).children()
.length > 0) {
$(this).before('<h3 class="facet-label" data-for="' + facet_name + '">' +
facet_label + '</h3>');
}
});
});
})(jQuery);
</script>
<?php
}
add_action( 'wp_head', 'fwp_add_facet_labels', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment