Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. /*
  2. Plugin Name: Redirect Main Site To Sub-Site
  3. Description: Redirect 'main-site' to 'main-site/sub-site/'
  4. Version: 0.1
  5. Author: WPSE
  6. Author URI: http://wordpress.stackexchange.com
  7. License: GPL2
  8. */
  9.  
  10. add_action('parse_request', 'redirect_to_sub_site');
  11. function redirect_to_sub_site(){
  12. global $wp;
  13.  
  14. #Sniff requests for a specific slug
  15. if('main-site' === $wp->request){
  16.  
  17. #The URL to redirect TO
  18. $url = 'http://www.example.com/main-site/sub-site/';
  19.  
  20. #Let WordPress handle the redirect - the second parameter is obviously the status
  21. wp_redirect($url, 301);
  22.  
  23. #It's important to exit, otherwise wp_redirect won't work properly
  24. exit;
  25. }
  26. }
  27.  
  28. #Sniff requests for a specific slug
  29. if('main-site' === $wp->request){
  30.  
  31. #The URL to redirect TO
  32. $url = 'http://www.example.com/main-site/sub-site/';
  33.  
  34. #Let WordPress handle the redirect - the second parameter is obviously the status
  35. wp_redirect($url, 301);
  36.  
  37. #It's important to exit, otherwise wp_redirect won't work properly
  38. exit;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement