Ido Fishman
I am trying to: switch theme based on ICL_LANGUAGE_CODE, I have 2 lang, EN and HE, when i switch to EN from HE lang it still call theme files for HE lang even i have used wp switch_theme function to change theme automatically.
URL of (my) website where problem appears:
hidden link
Here is the switch theme code added in both theme functions.php file:
<?php
function themeSwitcher(){
global $wpdb;
if(ICL_LANGUAGE_CODE == 'he'){
if($currentTheme !== "join"){
wp_cache_flush();
$wpdb->flush();
switch_theme( "join") ;
wp_cache_flush();
$wpdb->flush();
}
}else{
if($currentTheme !== "join_en"){
wp_cache_flush();
$wpdb->flush();
switch_theme( "join_en") ;
wp_cache_flush();
$wpdb->flush();
}
}
}
themeSwitcher();
?>
Tia
Hello. Thank you for contacting WPML Support. I am happy to help you with this.
Where is the variable $currentTheme defined at?
Ido Fishman
Hello Tia,
Here is the updated code:
function custom_load_twenty_ten_template() {
if(ICL_LANGUAGE_CODE == "en"){
return 'join_en';
}else{
return 'join';
}
}
function custom_load_twenty_ten_stylesheet() {
if(ICL_LANGUAGE_CODE == "en"){
return 'join_en';
}else{
return 'join';
}
}
add_filter( 'template', 'custom_load_twenty_ten_template' );
add_filter( 'stylesheet', 'custom_load_twenty_ten_stylesheet' );
$currentTheme = get_stylesheet();
function themeSwitcher(){
global $wpdb;
if(ICL_LANGUAGE_CODE == 'he'){
if($currentTheme !== "join"){
wp_cache_flush();
$wpdb->flush();
switch_theme( "join") ;
wp_cache_flush();
$wpdb->flush();
}
}else{
if($currentTheme !== "join_en"){
wp_cache_flush();
$wpdb->flush();
switch_theme( "join_en") ;
wp_cache_flush();
$wpdb->flush();
}
}
}
if(!is_admin()){
themeSwitcher();
}
Thanks,
Rahil
Tia
It appears $currentTheme is not defined in the function.
Either add:
global $wpdb, $currentTheme;
or define it within the function.
Ido Fishman
I did javascript page reload to fix this