Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global $wp_filter;
- if(is_array( $wp_filter['template_redirect'][11]['icl_redirect_canonical_wrapper'])) {
- remove_action('template_redirect', 'icl_redirect_canonical_wrapper', 11);
- add_action('template_redirect', 'mwi_redirect_canonical_wrapper', 11);
- function mwi_redirect_canonical_wrapper() {
- global $_icl_server_request_uri, $wp_query;
- $requested_url = ( !empty($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
- $requested_url .= $_SERVER['HTTP_HOST'];
- $requested_url .= $_icl_server_request_uri;
- // makes sure the canonical redirect isn't triggered when the current request is a non-recognized pagination (illegal/unknown page number).
- // this is a workaround that helps providing constant behavior of redirect_canonical()
- // "/en/page-other-lang/page/9999/" --> redirects to "/en/page-other-lang/"
- // "/page-primary-lang/page/9999/" --> just gives 404
- if( is_404() == true && is_paged() == false && count($wp_query->posts) == 0 && intval(get_query_var( 'paged' )) > 1 )
- return;
- redirect_canonical($requested_url);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement