By: Prem Tiwari | Last Updated: | In: WordPress Snippets
In this tutorial, I will explain how to enable/disable auto login when a user registered with your WordPress sites. This is simple WordPress snippets which allows you to disable/enable auto-login to your WordPress site.
Sometimes we need to disable or enable the auto login once the registration process is completed. Auto-login reduces the one extra steps after the register on your WordPress site.
Use the below code inside the wp-content/themes/your-theme-folder/functions.php file and save it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php /** * Function to disable auto login after user register */ function disable_auto_login_after_register( $user_id ) { wp_set_current_user( $user_id ); wp_clear_auth_cookie($user_id); //You can change home_url() to the specific URL wp_redirect( home_url() ); exit(); } add_action( 'user_register', 'disable_auto_login_after_register' ); ?> |
Copy below code and paste it at the end of the wp-content/themes/your-theme-folder/functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php /** * Function to enable auto login after user register */ function auto_login_new_user( $user_id ) { wp_set_current_user($user_id); wp_set_auth_cookie($user_id); //You can change home_url() to the specific URL,such as //wp_redirect( 'https://www.freewebmentor.com' ); wp_redirect( home_url() ); exit; } add_action( 'user_register', 'auto_login_new_user' ); ?> |
Hope this tutorial help you! Do like and share this tutorial with your friends and don’t forget to subscribe my blog to learn the cool WordPress tips & trick.
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari
Tags: wordpress auto login, wordpress disable auto login, wordpress login, wordpress register, wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials, wordpress tutorials for beginners