Last active
June 11, 2020 13:40
-
-
Save RiodeJaneiroo/ce8e90f636af7c250256915e248a94ec to your computer and use it in GitHub Desktop.
[Wordpress SEO redirect from any symbol ] 301 redirect from wrong url #seo #yoast #wordpress #redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wrong_url_redirect($url) { | |
global $wp; | |
if(!get_query_var('paged') && !empty($url) && !is_front_page() && $url != home_url($wp->request . '/' ) && !is_search()) { | |
wp_safe_redirect( $url, 301 ); | |
exit; | |
} | |
return $url; | |
} | |
add_filter( 'wpseo_canonical', 'wrong_url_redirect' ); | |
add_action( 'init', function() { | |
remove_filter( 'template_redirect', 'redirect_canonical' ); | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wrong_url_redirect($url) { | |
if(is_page() || is_single() || is_tax() || is_archive() ) { | |
global $wp; | |
if(!get_query_var('paged') && !empty($url) && empty($_GET) && !is_front_page() && $url != home_url($wp->request) && !is_search()) { | |
wp_safe_redirect( $url, 301 ); | |
exit; | |
} | |
} | |
return $url; | |
} | |
add_filter( 'wpseo_canonical', 'wrong_url_redirect' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wrong_url_redirect() { | |
if(is_page() || is_single() || is_tax() || is_archive() ) { | |
global $wp; | |
$url = get_the_permalink(87); | |
if(!get_query_var('paged') && !empty($url) && empty($_GET) && !is_front_page() && $url != (home_url($wp->request).'/') && !is_search()) { | |
wp_redirect( $url, 301 ); | |
exit; | |
} | |
} | |
} | |
add_filter( 'template_redirect', 'wrong_url_redirect' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment