<?php
/**
* add labels above facets by changing shortcode output
* this will apply to all facets except $exclude_types set below
* change or remove conditional to apply this to whichever facets needed
* wrapper can also be added
*/
add_filter( 'facetwp_shortcode_html', function( $output, $atts ) {
if ( isset( $atts["facet"] ) && '' != $atts["facet"] ) { // check for facet shortcode
$exclude_types = [ 'sort', 'reset', 'pager', 'map' ]; // set facet types to exclude from labels
$facet = FWP()->helper->get_facet_by_name( $atts["facet"] ); // get facet settings
if ( !in_array( $facet["type"], $exclude_types ) ) { // conditional to exclude types in $exclude_types
$output = '<h3 class="facet-label">' . $facet["label"] . '</h3>' . $output; // prepend with label and markup
// uncomment below to add facet-wrap
// $output = '<div class="facet-wrap">' . $output . '</div>';
}
}
return $output;
}, 10, 2 );