Last active
June 7, 2020 13:10
-
-
Save cubehrends/a9441883a2dd14f0ee91975c6ffdea91 to your computer and use it in GitHub Desktop.
301 Moved Permanently via WordPress Child Theme functions.php
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
<?php | |
function redirect_to_url() { | |
switch ( $_SERVER['REQUEST_URI'] ) { | |
case '/an-old-uri/': | |
$redirect_to = '/the-new-uri/'; | |
break; | |
case '/another-old-uri/': | |
$redirect_to = '/another-new-uri/'; | |
break; | |
default: | |
$redirect_to = false; | |
} | |
if ( $redirect_to && ! is_user_logged_in() ) { | |
if ( wp_safe_redirect( $redirect_to, 301 ) ) { exit; } | |
} | |
} | |
add_action( 'template_redirect', 'redirect_to_url' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment