How to auto redirect to the front page after login

Sometimes I’d like to go straight to my front page after logging in. This is extremely useful with themes like P2 which allow you to post from the front page, but may also come in handy if you don’t want your users to be put off by the admin interface.

There’s a very effective solution built right into WordPress. Usually you’d login with something like this:

http://yourdomain.com/wp-admin

This in turn is a shortcut that really calls the actual php file:

http://yourdomain.com/wp-login.php

To redirect to the front page after login, just change that to

http://yourdomain.com/wp-login.php?redirect_to=http://yourdomain.com/

Thanks to Otto for this suggestion in the WordPress forums.

You can either bookmark this link or add it anywhere in your theme so you and your users can access it easily. If you’d like to build it right into a theme and call this via PHP you can make use of functions that generate the correct URLs for you:

// Link to the front page:
echo wp_login_url( home_url() );

// Link to the current page (any page or post):
echo wp_login_url( get_permalink() );

More info in the WordPress Codex:
http://codex.wordpress.org/Function_Reference/wp_login_url





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.