In LearnDash if you would like to redirect a user to another page once a user completes a course.
Getting Started #
Our documentation will require PHP and/or JavaScript code. To use the code you must place it in your WordPress code in an appropriate place to load, usually in a theme or plugin.
PHP #
PHP code can be placed in your theme’s functions.php file, or in a standalone plugin if you know how to make one.
JavaScript #
JavaScript code should be placed in a JavaScript file (.js) and enqueued using wp_enqueue_scripts. There are other ways of getting JavaScript on the page, but this is the most recommended to avoid future problems with JavaScript code on the page.
Documentation #
apply_filters( 'learndash_course_completion_url', $next_quiz, $course_id )
- $next_quiz – INT | String – ID or URL of the next quiz or course where users will be redirected
- $course_id – INT – Course ID to redirect from
Example #
function learndash_course_redirect( $link, $course_id ) {
// You can change the link here
if ( $course_id == 123 ) {
$link = get_permalink( 456 );
} elseif ( $course_id == 456 ) {
$link = get_permalink( 789 );
}
// Always return $link
return $link;
}
add_filter( 'learndash_course_completion_url', 'learndash_course_redirect', 5, 2 );
The callback function, learndash_course_redirect should return a URL (string) or ID (int) of where to send the user.