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>
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
Automatically redirect to current page after login