# 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.

- Type: PHP
- Runs: Frontend only
- Category: [Performance](https://wpide.com/library/category/performance/)
- Tags: performance, comments, javascript
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/comment-reply-script-when-needed/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Load comment-reply.js Only When Needed" 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/
