Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Load the comment reply script only when needed

Loads WordPress’s comment-reply script only on posts with open, threaded comments, instead of whenever a theme asks for it.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Performance
  • Tested with WordPress 7.1
PHP
<?php

add_action(
	'wp_enqueue_scripts',
	static function () {
		if ( ! is_singular() || ! comments_open() || ! get_option( 'thread_comments' ) ) {
			wp_dequeue_script( 'comment-reply' );
		}
	},
	100
);

In these packs

  • More speed: More ways to load less: block styles, speculative loading, fewer scripts.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.