Advertisement
mbis

Fix language mismatch (redirect)

Jan 4th, 2023
1,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. //redirect if the language mismatch in URL is detected
  2. function pm_lang_mismatch_redirect() {
  3.     global $permalink_manager_uris, $pm_query, $wp_query;
  4.  
  5.     if(!empty($pm_query['id'])) {
  6.         $element_id = (is_singular()) ? $pm_query['id'] : "tax-{$pm_query['id']}";
  7.        
  8.         $element_uri = $permalink_manager_uris[$element_id];
  9.         $request_uri = $pm_query['uri'];
  10.    
  11.         if($element_uri !== $request_uri) {
  12.             $wp_query->query_vars['do_not_redirect'] = 0;
  13.         }
  14.     }
  15. }
  16. add_action('template_redirect', 'pm_lang_mismatch_redirect', 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement