# LearnDash: Keep Lessons and Quizzes Out of Site Search

> Removes LearnDash lessons, topics, quizzes and certificates from your site's search results so visitors only find courses, not locked lesson pages.

- Type: PHP
- Runs: Frontend only
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: learndash, search, courses
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/learndash-exclude-steps-from-search/

## Code

```php
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
    return;
}

// Post types to hide from search.
$wpide_ld_hidden_types = array( 'sfwd-lessons', 'sfwd-topic', 'sfwd-quiz', 'sfwd-certificates', 'sfwd-question' );

add_action( 'pre_get_posts', function ( $query ) use ( $wpide_ld_hidden_types ) {
    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, $wpide_ld_hidden_types ) ) );
} );
```

## Notes

Courses stay searchable. Add sfwd-courses to the list to hide those too.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Keep Lessons and Quizzes Out of Site Search" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
