Contents
Snippet #
Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.
/* Redirect users who aren’t logged in to Specified URL when they attempt to access a specific LearnDash course */
add_action( 'template_redirect', function() {
// Specify the course ID for which the redirection should occur.
$target_course_id = 123; // Replace 123 with your specific course ID.
// This will check if the current user is not logged in and if the course ID matches.
if ( ! is_user_logged_in() && is_singular( 'sfwd-courses' ) && get_the_ID() === $target_course_id ) {
// Replace https://learndash.com/ with the URL of your custom page where users will be redirected when accessing the target_course_id.
wp_redirect( 'https://learndash.com' );
exit;
}
} );