Last active
January 21, 2021 15:35
-
-
Save djrmom/59824c8e9fbf972379be08fbda2df9a0 to your computer and use it in GitHub Desktop.
facetwp html replace labels/choices for wmpl or polylang
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 | |
/** find replace for wmpl sites for labels/choices in filters **/ | |
add_filter( 'facetwp_facet_html', function( $output, $params ) { | |
if ( 'my_facet_name' == $params['facet']['name'] ) { | |
$current = ( !empty( FWP()->facet->http_params['lang'] ) ) ? FWP()->facet->http_params['lang'] : apply_filters( 'wpml_current_language', null ); | |
$default = apply_filters('wpml_default_language', NULL ); | |
// use these 2 lines instead of 2 above for polylang | |
//$current = ( !empty( FWP()->facet->http_params['lang'] ) ) ? FWP()->facet->http_params['lang'] : pll_current_language(); | |
//$default = pll_default_language(); | |
$replace_values = []; | |
$replace_values['nl'] = [ | |
'Belgium' => 'België', | |
'Bulgaria' => 'Bulgarije' | |
]; | |
if ( $current != $default && !empty( $replace_values[$current] ) ) { | |
$default_values = []; | |
$new_values = []; | |
foreach ( $replace_values[$current] AS $replace_value => $replacement ) { | |
$default_values[] = $replace_value; | |
$new_values[] = $replacement; | |
} | |
$output = str_replace( $default_values, $new_values, $output ); | |
} | |
} | |
return $output; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment