Load comment-reply.js Only When Needed
Stops the threaded comments script from loading on pages that have no open comments or where threading is turned off.
Opens WPIDE on
Code
add_action( 'wp_enqueue_scripts', function () {
$needed = is_singular() && comments_open() && get_option( 'thread_comments' );
if ( ! $needed ) {
wp_dequeue_script( 'comment-reply' );
}
}, 100 );
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.