DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

When building a site using WordPress, you often need to redirect the user to the login page. Today, I’m going to show you how you can easily redirect the user to the current page after login.

WordPress have a great function named wp_login_url(). This function displays a link to your dashboard login page. It accept one parameter: an url to redirect after the user successfully logged in. By using get_permalink() as a parameter, you’ll redirect the user to the current page.

<a href="<?php echo wp_login_url(get_permalink()); ?>" title="Login">Login to view</a>

Leave a Comment

Your email address will not be published. Required fields are marked *