Skip to content
wp-skills
Register
tools/register-enqueue-scripts

Register Enqueue Scripts Generator

WordPress Register Enqueue Scripts Generator lets you easily add customized functionality to your WordPress site by uploading external JavaScript files.

Give it a prefix of your own. Two snippets sharing a function name is a fatal redeclaration.

Which screens the scripts load on. Each is a different hook, and the front end and the admin do not share one.

Scripts1
  • #1

    The handle. It is what other scripts list as a dependency, and what wp_localize_script() addresses.

    How the source is resolved. A child theme's own assets are not under get_template_directory_uri() — that points at the parent.

    A leading slash is optional; both spellings produce the same URL.

    Comma-separated handles. WordPress loads these first — a script that needs jQuery and does not say so is a race, not a bug you can reproduce.

    Appended as ?ver= and is what busts a browser cache. false uses the WordPress version, which changes on every core update.

    In the footer is the default worth keeping: a script in the head blocks rendering until it has been fetched and run.

    WordPress 6.3. defer runs after parsing, in order; async runs whenever it arrives, so it suits scripts nothing else depends on.

snippet.php
function my_enqueue_scripts() {
	wp_enqueue_script(
		'my-script',
		get_template_directory_uri() . '/assets/js/my-script.js',
		array('jquery'),
		'1.0',
		true
	);
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );