Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active August 18, 2017 12:31
Show Gist options
  • Save djrmom/2032807e697daf368a478e7b5b62f99c to your computer and use it in GitHub Desktop.
Save djrmom/2032807e697daf368a478e7b5b62f99c to your computer and use it in GitHub Desktop.
facetwp hash for colors
//filter color display to maybe add hash to hex colors
add_filter( 'facetwp_facet_render_args', function( $args ) {
if ( 'colors' == $args['facet']['name'] ) {
foreach ( $args['values'] AS $key => $value ) {
$args['values'][$key]['facet_display_value'] = ( '' != ( $color = sanitize_hex_color_no_hash( $value['facet_display_value'] ) ) ) ? '#' . $color : $value['facet_display_value'];
}
}
return $args;
});
//filter color index to maybe add hash to hex colors
add_filter( 'facetwp_index_row', function( $params ) {
if ( 'colors' == $params['facet_name'] ) {
$display_value = $params['facet_display_value'];
$params['facet_display_value'] = ( '' != ( $color = sanitize_hex_color_no_hash( $params['facet_display_value'] ) ) ) ? '#' . $color : $params['facet_display_value'];
}
return $params;
}, 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment