Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active January 21, 2021 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/59824c8e9fbf972379be08fbda2df9a0 to your computer and use it in GitHub Desktop.
Save djrmom/59824c8e9fbf972379be08fbda2df9a0 to your computer and use it in GitHub Desktop.
facetwp html replace labels/choices for wmpl or polylang
<?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