# LearnDash: Turn Off Comments on Lessons and Quizzes

> Closes comments on LearnDash lessons, topics and quizzes, and hides existing ones, while leaving comments on courses and blog posts alone.

- Type: PHP
- Runs: Run everywhere
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: learndash, comments, courses
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/learndash-close-comments-on-steps/

## Code

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

$wpide_ld_no_comment_types = array( 'sfwd-lessons', 'sfwd-topic', 'sfwd-quiz' );

add_filter( 'comments_open', function ( $open, $post_id ) use ( $wpide_ld_no_comment_types ) {
    return in_array( get_post_type( $post_id ), $wpide_ld_no_comment_types, true ) ? false : $open;
}, 10, 2 );

add_filter( 'get_comments_number', function ( $count, $post_id ) use ( $wpide_ld_no_comment_types ) {
    return in_array( get_post_type( $post_id ), $wpide_ld_no_comment_types, true ) ? 0 : $count;
}, 10, 2 );
```

## Notes

Remove a post type from the list to keep its comments open.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Turn Off Comments on Lessons and Quizzes" 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/
