Apologies for the amateur questions, but I'm struggling a bit in WordPress grateful for any help.
I have built a LMS site using LearnDash. The homepage is simply a login, so I have added the following to functions.php
:
function admin_redirect() {
if ( !is_user_logged_in()) {
wp_redirect( home_url('login') );
exit;
}
}
add_action('get_header', 'admin_redirect');
I have set the front page to be the learner profile. I assumed users would get redirected to this when they login but they drop into the wp-admin dashboard (which I never want non-admins to see).
Because my coding skills are pants, I've installed the 'Peter's Login Redirect' and asked it to redirect users to the home page / front page (which is the user profile page).
I've then tried it across different browsers and sometimes I'm getting to the front page / user profile but sometimes I'm getting dropped back into WP-Admin. I've tried incognito mode, clearing cookies etc.
I'm obviously being a muppet - as what I want is very simple:
- All users - force login
- Non-admins - from login go to front page with user profile (via Learndash short code)
- Admins - from login go to admin dashboard / wp-admin
Grateful, if anyone has the time to help out an amateur trying to learn!