<?php
/** adds a span to checkbox labels for styling **/
add_filter( 'facetwp_facet_html', function( $html, $args ) {
if ( 'checkboxes' == $args['facet']['type']) {
$pattern = '/<div class="facetwp-checkbox[^"]*" data-value="[^"]*">([^<]*) <span/';
preg_match_all( $pattern, $html, $matches );
if ( !empty($matches[1]) ) {
foreach ( $matches[1] AS $label ) {
$html = str_replace( '>' . $label . ' <span', '><span class="fwp_label">' . $label . '</span> <span', $html );
}
}
}
return $html;
}, 10, 2);
/** add span for styling to radio labels **/
add_filter( 'facetwp_facet_html', function( $html, $args ) {
if ( 'radio' == $args['facet']['type']) {
$pattern = '/<div class="facetwp-radio[^"]*"[^>]*>([^<]*)s?</';
preg_match_all( $pattern, $html, $matches );
if ( !empty($matches[1]) ) {
foreach ( $matches[1] AS $label ) {
$html = str_replace( '>' . $label, '><span class="facetwp-radio-label">' . $label . '</span>', $html );
}
}
}
return $html;
}, 10, 2);