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.
Opens WPIDE on
Code
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 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.