When working with WPML the other day I ran into the following issue. I had to redirect the visitor to the preferred language translated page, based on an url. This also ment that at the point of redirecting there no post id yet know.
I wrote the following function to solve the problem described above.
function get_url_for_language( $original_url, $language ) { $post_id = url_to_postid( $original_url ); $lang_post_id = icl_object_id( $post_id , 'page', true, $language ); $url = ""; if($lang_post_id != 0) { $url = get_permalink( $lang_post_id ); }else { // No page found, it's most likely the homepage global $sitepress; $url = $sitepress->language_url( $language ); } return $url; }
Thanks!, Excellent function 😀
thx!
Oh man…
You are a savior! 🙂
ty bro
Thanks ! You are Great bro…
nice