Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active April 9, 2020 15:07
Show Gist options
  • Save djrmom/cef434837e48ef36a7978ba037bc3bf4 to your computer and use it in GitHub Desktop.
Save djrmom/cef434837e48ef36a7978ba037bc3bf4 to your computer and use it in GitHub Desktop.
facetwp add span to labels
<?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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment