learndash_show_next_link
Filters whether the "Next" link is displayed for a lesson or topic.
add_filter( 'learndash_show_next_link', $callback, 10, 3 );
Description
Filters whether the "Next Lesson" link should be displayed. Useful for conditionally hiding the link based on user progress or other custom logic. This hook fires in the single lesson template.
Usage
add_filter( 'learndash_show_next_link', 'your_function_name', 10, 3 );
Parameters
-
$user_id(mixed) - This parameter is the ID of the user for whom the next lesson link visibility is being determined.
-
$user_id(mixed) - This parameter contains the ID of the user for whom the next lesson link is being displayed.
-
$post(mixed) - This parameter contains the user ID for whom the next link visibility is being determined.
Return Value
The filtered value.
Examples
add_filter(
'learndash_show_next_link',
function( $show_next_link, $user_id, $post_id ) {
// Example: Conditionally hide the "Next" link if the user is a guest
// or if a specific custom meta field is set on the lesson.
if ( ! is_user_logged_in() ) {
return false; // Hide for guest users.
}
// Get custom meta for the lesson (replace 'my_custom_hide_next_link' with your actual meta key)
$hide_next_link_meta = get_post_meta( $post_id, 'my_custom_hide_next_link', true );
if ( ! empty( $hide_next_link_meta ) && 'yes' === $hide_next_link_meta ) {
return false; // Hide if the custom meta indicates to hide.
}
// If not hidden by the above conditions, return the original decision.
return $show_next_link;
},
10,
3 // $show_next_link, $user_id, $post_id
);
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/templates/single-lesson.php:171
<?php
/*
* See details for filter 'learndash_show_next_link' https://bitbucket.org/snippets/learndash/5oAEX
*
* @since version 2.3
*/
?>
<?php if ( apply_filters( 'learndash_show_next_link', learndash_is_lesson_complete( $user_id, $post->ID ), $user_id, $post->ID ) ) { ?>
<?php echo learndash_next_post_link(); ?>
<?php } ?>
</p>