Advertisement
Guest User

Untitled

a guest
Apr 12th, 2013
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. global $wp_filter;
  2.  
  3. if(is_array( $wp_filter['template_redirect'][11]['icl_redirect_canonical_wrapper'])) {
  4.  
  5.     remove_action('template_redirect', 'icl_redirect_canonical_wrapper', 11);
  6.     add_action('template_redirect', 'mwi_redirect_canonical_wrapper', 11);
  7.  
  8.     function mwi_redirect_canonical_wrapper() {
  9.         global $_icl_server_request_uri, $wp_query;
  10.         $requested_url  = ( !empty($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
  11.         $requested_url .= $_SERVER['HTTP_HOST'];
  12.         $requested_url .= $_icl_server_request_uri;
  13.  
  14.         // makes sure the canonical redirect isn't triggered when the current request is a non-recognized pagination (illegal/unknown page number).
  15.             // this is a workaround that helps providing constant behavior of redirect_canonical()
  16.             // "/en/page-other-lang/page/9999/" --> redirects to "/en/page-other-lang/"
  17.             // "/page-primary-lang/page/9999/" --> just gives 404
  18.         if( is_404() == true && is_paged() == false && count($wp_query->posts) == 0 && intval(get_query_var( 'paged' )) > 1  )
  19.             return;
  20.  
  21.         redirect_canonical($requested_url);
  22.  
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement