Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by Ido Fishman 5 years ago.

Assigned support staff: Tia.

Author Posts
February 4, 2016 at 9:42 am #804635

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();

?>

February 4, 2016 at 9:03 pm #805344

Tia

Hello. Thank you for contacting WPML Support. I am happy to help you with this.

Where is the variable $currentTheme defined at?

February 5, 2016 at 7:14 am #805511

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

February 5, 2016 at 9:21 pm #806299

Tia

It appears $currentTheme is not defined in the function.

Either add:
global $wpdb, $currentTheme;

or define it within the function.

February 6, 2016 at 7:50 am #806388

Ido Fishman

I did javascript page reload to fix this