I am new to wordpress. I am running wordpress setup on http://localhost/wordpress/. I am facing two problems right now:
- Only the logged in users can access the site. So, I am trying to redirect the user from home page to login page using the following code which is somehow isn't working:
Path:
wp-content/themes/twentysixteen/header.php
<?php
if(get_permalink() != wp_login_url() && !is_user_logged_in()){
wp_redirect( wp_login_url() ); exit;
}
?>
Since the above code wasn't working, I tried to move on by letting the user to login manually by clicking on the login button. Here is the working code:
<?php
if(get_permalink() != wp_login_url() && !is_user_logged_in()){
// wp_redirect( wp_login_url() ); exit;
?>
<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>
<?php
}
?>
- From above code, when user clicked on login he was redirected to login page and When the user is logs in, the page is redirecting to wordpress admin i.e
wp-admininstead of home page i.ehttp://localhost/wordpress.
What I am trying to do is:
- Redirect the user from home page to login page, if the user isn't logged in.
- And then redirect the user from login page to home page instead of wp-admin, when user logs in.