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>