redirect after login

A common question I’ve seen is how can you redirect a user to a specific URL after they login to WordPress. Maybe you want to hide the Admin Dashboard from your users, so redirecting them to the home page after logging in is a great way to do this. Just place the below code in your themes functions.php file:

01 <?php
02 add_action('login_form', 'redirect_after_login');
03
04 function redirect_after_login() {
05 global $redirect_to;
06 if (!isset($_GET['redirect_to'])) {
07 $redirect_to = get_option('siteurl');
08 }
09 }
10 ?>

The preceding code snippet will redirect any user who logs in to the home page (siteurl) of WordPress. You can easily set any redirect URL you want by changing the value of the $redirect_to variable. This function also verifies that the redirect_to querystring doesn’t exist before setting the redirect URL.

It’s as easy as that! Now you can easily control where your users are redirected to when they login to WordPress.