Last active
April 9, 2020 15:07
-
-
Save djrmom/cef434837e48ef36a7978ba037bc3bf4 to your computer and use it in GitHub Desktop.
facetwp add span to 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 | |
/** 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