Redirect user after login

NextGEN Gallery review

Adding this snippet to the functions.php of your wordpress theme will redirect the user to your homepage after they login.

add_action('login_form', 'redirect_after_login');

function redirect_after_login() {
	global $redirect_to;
	if (!isset($_GET['redirect_to'])) {
		$redirect_to = get_option('siteurl');

Comments  Leave a Reply

  1. This is brilliant, thanks so much for sharing! I was wondering if it’s possible to take it a step further and have the user redirected to a page specifically for them? for example: each user has a page created in their name and after login they are redirected to that specific page? Maybe a custom field could be used to differentiate the pages?

    My knowledge of php and wordpress doesn’t quite stretch this far, so pointers would be really helpful.


    1. Hi Ally, sure you could do this, if you auto create a page for each user you could just append to the url eg:


      this type of thing, cheers.

  2. elliottrichmond April 26, 2011 at 8:28 pm

    That’s a cool bit of code, how about if the user is Subscriber or if is a custom Role that would be useful for a project I’ve been working on recently. Basically if a user is a certain role they are redirected to a specific page?

    1. Sure you could do that easy enough give me a few ill email it to you.

      1. Can you send me this snipp that you said you would email to Elliot?

      2. I could also use this code for role specific redirection. How can I get it? Thanks.

  3. Marlon Amancio April 26, 2011 at 7:27 pm

    Tanks!!! I was looking for this.

    1. Cool glad I could help, you should subscribe to our rss feed or join our Facebook group and check out the snippets we add everyday.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!