Last active
          December 17, 2015 16:29 
        
      - 
      
 - 
        
Save ataylorme/5639434 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or 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 | |
| /* ========== 301 REDIRECTS ========== */ | |
| function my_wordpress_301_redirects() { | |
| /* Bail if on the front page */ | |
| if( is_front_page() ) | |
| return; | |
| $redirect_pages = array( | |
| /* Pass a string to redirect to a new page */ | |
| 'slug1' => 'new-slug1', | |
| 'slug2' => 'new-slug2', | |
| /* Pass false to redirect to the homepage */ | |
| 'slug3' => false, | |
| 'slug4' => false, | |
| 'slug5.xml' => 'new-slug3.xml', | |
| 'slug6.php' => 'new-slug4.php', | |
| 'slug7.html' => 'new-slug5.html' | |
| ); | |
| $slug = array_pop(array_filter(explode('/', $_SERVER["REQUEST_URI"]))); | |
| /* Bail if slug is empty */ | |
| if( empty($slug) ) | |
| return; | |
| foreach( $redirect_pages as $old=>$new ): | |
| if( $slug == $old ): | |
| if( $new == false ) | |
| wp_redirect( get_bloginfo('url'), 301 ); | |
| else | |
| wp_redirect( get_bloginfo('url') . '/' . $new . '/', 301 ); | |
| exit; | |
| endif; | |
| endforeach; | |
| } //end my_wordpress_301_redirects | |
| add_action( 'get_header', 'my_wordpress_301_redirects', 10 ); | |
| ?> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment