LifterLMS: Remove Lessons and Quizzes From Search Results
Removes LifterLMS lessons and quizzes from your site's search results so visitors find courses instead of locked lesson pages.
Opens WPIDE on
Code
if ( ! function_exists( 'llms_get_student' ) ) {
return;
}
add_action( 'pre_get_posts', function ( $query ) {
if ( is_admin() || ! $query->is_main_query() || ! $query->is_search() ) {
return;
}
$types = $query->get( 'post_type' );
if ( ! $types || 'any' === $types ) {
$types = get_post_types( array( 'exclude_from_search' => false ) );
}
$query->set( 'post_type', array_values( array_diff( (array) $types, array( 'lesson', 'llms_quiz' ) ) ) );
} );
Notes
Courses and memberships stay searchable.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.