Skip to content

Instantly share code, notes, and snippets.

@cubehrends
Last active June 7, 2020 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cubehrends/a9441883a2dd14f0ee91975c6ffdea91 to your computer and use it in GitHub Desktop.
Save cubehrends/a9441883a2dd14f0ee91975c6ffdea91 to your computer and use it in GitHub Desktop.
301 Moved Permanently via WordPress Child Theme functions.php
<?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