Skip to content

Instantly share code, notes, and snippets.

@ivankruchkoff
Created July 10, 2017 02:30
Show Gist options
  • Save ivankruchkoff/841885495873a1fe2ec0645b079f927e to your computer and use it in GitHub Desktop.
Save ivankruchkoff/841885495873a1fe2ec0645b079f927e to your computer and use it in GitHub Desktop.
function vip_substr_redirects( $vip_redirects_array = array(), $append_old_uri = false ) {
if ( empty( $vip_redirects_array ) )
return;
// Don't do anything for the homepage
if ( '/' == $_SERVER['REQUEST_URI'] )
return;
foreach ( $vip_redirects_array as $old_path => $new_url ) {
if ( substr( $_SERVER['REQUEST_URI'], 0, strlen( $old_path ) ) == $old_path ) {
if ( $append_old_uri )
$new_url .= str_replace( $old_path, '', $_SERVER['REQUEST_URI'] );
wp_redirect( $new_url, 301 );
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment