Funcion change current lenguage and page redirect
-
Hi!
I need to filter what language users in each country can see. I have to redirect a page if the country is not correct.
I found the code below, in the browser I can see that the language has changed but I still receive the same page and I can not access the page of the new language
PLL()->curlang = PLL()->model->get_language( 'de' );
I tried this and it didn’t work:
function get_correct_page() { if( get_location_geoIP() == 'DE') { $current = pll_current_language(); if( $current != 'de' ) { global $post; $post_id = $post->ID; $post_id = pll_get_post($post_id, 'de'); $url = get_permalink($post_id); PLL()->curlang = PLL()->model->get_language( 'de' ); wp_redirect($url); exit(); } } } add_action( 'wp', 'get_correct_page');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Funcion change current lenguage and page redirect’ is closed to new replies.