pusatdata

Disable Or Redirect WP-login.php

Dec 13th, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. Try this in your theme's functions.php
  2. ========================================
  3.  
  4. 1.-------------------------------
  5. add_action('init','custom_login');
  6. function custom_login(){
  7. global $pagenow;
  8. if( 'wp-login.php' == $pagenow ) {
  9. wp_redirect('http://yoursite.com/');
  10. exit();
  11. }
  12. }
  13.  
  14. 2. ---------------------------------
  15. // Hook the appropriate WordPress action
  16. add_action('init', 'prevent_wp_login');
  17.  
  18. function prevent_wp_login() {
  19. // WP tracks the current page - global the variable to access it
  20. global $pagenow;
  21. // Check if a $_GET['action'] is set, and if so, load it into $action variable
  22. $action = (isset($_GET['action'])) ? $_GET['action'] : '';
  23. // Check if we're on the login page, and ensure the action is not 'logout'
  24. if( $pagenow == 'wp-login.php' && ( ! $action || ( $action && ! in_array($action, array('logout', 'lostpassword', 'rp'))))) {
  25. // Load the home page url
  26. $page = get_bloginfo('url');
  27. // Redirect to the home page
  28. wp_redirect($page);
  29. // Stop execution to prevent the page loading for any reason
  30. exit();
  31. }
  32. }
  33.  
  34. 3. ---------------------------
  35. function custom_login_page() {
  36. $new_login_page_url = home_url( '/login/' ); // new login page
  37. global $pagenow;
  38. if( $pagenow == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
  39. wp_redirect($new_login_page_url);
  40. exit;
  41. }
  42. }
  43.  
  44. if(!is_user_logged_in()){
  45. add_action('init','custom_login_page');
  46. }
  47. This code snippet will:
  48.  
  49. Redirect all website visitors to new login page.
  50. Logout will work without any problem
  51. On your custom login page you will have to create custom login , registration and password reset forms, However your custom forms can safely post data to wp-login.php as post requests are not redirected.
Add Comment
Please, Sign In to add comment