How to auto redirect to the front page after login

- by

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



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.