Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created August 4, 2012 17:16
Show Gist options
  • Save danielbachhuber/3258825 to your computer and use it in GitHub Desktop.
Save danielbachhuber/3258825 to your computer and use it in GitHub Desktop.
Quick way to handle redirects for old pages
<?php
/**
* Quick way to handle redirects for old pages
*
* From Happiness Bar at WordCamp SF 2012
*/
add_action( 'init', 'mea_redirects' );
function mea_redirects() {
$mea_redirects = array(
// Enter your old URI => new URI
'/redundant_digital_control.html' => '/redundant-digital-control/',
);
foreach( $mea_redirects as $old_uri => $new_uri ) {
if ( false !== strpos( $_SERVER['REQUEST_URI'], $old_uri ) ) {
wp_safe_redirect( home_url( $new_uri ), 301 );
exit;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment