I am new to wordpress. I am running wordpress setup on http://localhost/wordpress/
. I am facing two problems right now:
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
}
?>
wp-admin
instead of home page i.e http://localhost/wordpress
.To redirect the user from homepage to login page, you can use Wordpress function is_user_logged_in,
https://developer.wordpress.org/reference/functions/is_user_logged_in/
if(!is_user_logged_in()) {
wp_redirect( wp_login_url() );
}
To redirect user on homepage rather Dashboard, you can follow already posted solution on Stack overflow.
https://wordpress.org/support/topic/how-can-i-redirect-users-to-the-front-page-after-log-in
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With