Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Try this in your theme's functions.php
- ========================================
- 1.-------------------------------
- add_action('init','custom_login');
- function custom_login(){
- global $pagenow;
- if( 'wp-login.php' == $pagenow ) {
- wp_redirect('http://yoursite.com/');
- exit();
- }
- }
- 2. ---------------------------------
- // Hook the appropriate WordPress action
- add_action('init', 'prevent_wp_login');
- function prevent_wp_login() {
- // WP tracks the current page - global the variable to access it
- global $pagenow;
- // Check if a $_GET['action'] is set, and if so, load it into $action variable
- $action = (isset($_GET['action'])) ? $_GET['action'] : '';
- // Check if we're on the login page, and ensure the action is not 'logout'
- if( $pagenow == 'wp-login.php' && ( ! $action || ( $action && ! in_array($action, array('logout', 'lostpassword', 'rp'))))) {
- // Load the home page url
- $page = get_bloginfo('url');
- // Redirect to the home page
- wp_redirect($page);
- // Stop execution to prevent the page loading for any reason
- exit();
- }
- }
- 3. ---------------------------
- function custom_login_page() {
- $new_login_page_url = home_url( '/login/' ); // new login page
- global $pagenow;
- if( $pagenow == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
- wp_redirect($new_login_page_url);
- exit;
- }
- }
- if(!is_user_logged_in()){
- add_action('init','custom_login_page');
- }
- This code snippet will:
- Redirect all website visitors to new login page.
- Logout will work without any problem
- 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