Archived topic
Translate Cookie Notice with WPML
4 replies · Started by Sergio on September 28, 2018
Hi there,
I´m using Elements to create a cookie consent I created with Cookie Consent by Insites. I already made Elements translatable, but since they both have the the Display Rule set to Entire Site, the 2 of them show up in both languages. I thought of manually selecting the pages, but I use a Calendar plugin that creates multiple entries, so it would be impossible to do this.
Any ideas?
Thanks a lot!
Sorry I forgot to mencione I´m using WPML to translate. Also, the importance of translating the cookie consent is because the Privacy Policy is in both languages.
Hi there,
What if you do something like this?:
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
// Target our German Hook Element with the ID: 10
if ( 10 === $element_id ) {
if ( 'de_DE' === get_locale() ) {
return true;
} else {
return false;
}
}
// Target our English Hook Element with the ID: 20
if ( 20 === $element_id ) {
if ( 'de_DE' !== get_locale() ) {
return true;
} else {
return false;
}
}
return $display;
}, 10, 2 );
You'd obviously have to update the de_DE to your locale, and the IDs of the hook elements.
Let me know :)
Where should this code go? In the functions.php of my child theme?
Thanks.
Yup that will work.