You could try something like this to add a custom form field:
add_action('login_form', 'custom_login_field');
function custom_login_field() {
if (!is_singular('course')) {
echo "<input type="hidden" name="context" value="notcourse">";
}
}
Which is then picked up if it is set and does the redirect on login:
add_action('wp_login', 'auto_redirect_after_login');
function auto_redirect_after_login() {
if ( (isset($_POST['context'])) && ($_POST['context'] == 'notcourse') ) {
wp_redirect(home_url()); exit();
}
}
So that any login form submitted from a non-course page will redirect to home after login as this seems to be what you are intending.
UPDATE
Switching the logic around might work instead:
add_action('login_form', 'custom_login_field');
function custom_login_field() {
if (is_singular('course')) {
echo "<input type="hidden" name="context" value="course">";
}
}
add_action('wp_login', 'auto_redirect_after_login');
function auto_redirect_after_login() {
if ( (isset($_POST['context'])) && ($_POST['context'] == 'course') ) {
return;
}
wp_redirect(home_url()); exit();
}