Tutor LMS: Keep Lessons Out of Site Search
Removes Tutor LMS lessons, quizzes and assignments from your site search so visitors land on course pages instead.
Opens WPIDE on
Code
if ( ! function_exists( 'tutor' ) ) {
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( tutor()->lesson_post_type, 'tutor_quiz', 'tutor_assignments' ) ) ) );
} );
Notes
Courses 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.