Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsUse WordPress’s enqueue system to add reusable JavaScript and CSS: call wp_enqueue_script() or wp_enqueue_style() from the hook for the page context, and declare each asset’s dependencies. For a small inline snippet, attach it to an enqueued asset with WordPress’s inline helpers rather than printing tags directly into a template.
Why enqueue assets instead of adding tags to a template?
Enqueueing lets WordPress manage asset output and dependencies alongside files added by the active theme and plugins. For theme styles, the WordPress Theme Handbook recommends this approach rather than hard-coding a stylesheet tag in header.php. It also gives WordPress the information it needs to order dependent scripts and styles.
Choose the hook based on where the asset is used: wp_enqueue_scripts for the public-facing site, and admin_enqueue_scripts for dashboard screens. The similarly named front-end hook is also used for styles.
Add front-end CSS and JavaScript in a theme
Put the files in your theme, then enqueue them from a named callback. This example assumes the files exist at the shown paths; replace the sample handles and version with project-specific values.
#1 Best Overall
function example_theme_assets() {
wp_enqueue_style(
'example-theme-main',
get_theme_file_uri( 'assets/css/main.css' ),
array(),
'1.0.0'
);
wp_enqueue_script(
'example-theme-main',
get_theme_file_uri( 'assets/js/main.js' ),
array(),
'1.0.0',
array( 'in_footer' => true )
);
}
add_action( 'wp_enqueue_scripts', 'example_theme_assets' );
The final arguments include the dependency list and version. For the script, the arguments array requests footer placement. If the JavaScript depends on jQuery or another registered script, put that script’s registered handle in the dependency array; for styles, list any stylesheet handles the new stylesheet depends on. WordPress uses these relationships to determine load order. A dependency that is not registered cannot be loaded for the dependent script.
Use the right approach for plugins and admin screens
Plugin front-end assets
Enqueue a plugin’s public-facing files on wp_enqueue_scripts. Build the asset URL from the plugin’s own location, for example with plugins_url(), rather than assuming a theme-relative path. This keeps the asset reference tied to the plugin that owns the file.
Dashboard-only assets
Enqueue admin JavaScript or CSS on admin_enqueue_scripts. If an asset is needed on only one dashboard screen, check the current admin screen in the callback and enqueue it only there; this avoids loading unrelated code across the admin area.
Registering versus enqueueing
Use registration when another part of the code will enqueue the asset later or when it is needed conditionally. Registering an asset describes it to WordPress but does not, by itself, add it to page output; it must also be enqueued.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Rank #3
Set handles, dependencies, and versions deliberately
- Handles: Give every asset a descriptive handle that is unique within the project. Other scripts or styles use these handles to declare dependencies.
- Dependencies: List registered handles that must be available first. This lets WordPress order assets instead of relying on coincidental tag order.
- Versions: Supply a useful version for cache busting. If a build workflow produces dependency and version metadata for compiled assets, use that output where appropriate rather than maintaining conflicting values by hand.
Do not list a library as a dependency merely because it is commonly used: the script must actually rely on it, and the handle must be registered in the site’s asset system.
Choose script placement and loading strategy based on execution needs
wp_enqueue_script() accepts an arguments array that can include in_footer and, starting with WordPress 6.3, a strategy value of defer or async.
Rank #4
| Choice | Behavior | Best suited to |
|---|---|---|
in_footer |
Requests that the script be placed in the footer rather than the head. | Scripts that do not need to be output in the document head. |
defer |
Runs after the document has been parsed and preserves execution order among deferred scripts. | Scripts that need ordered execution but can wait until parsing is complete. |
async |
Runs as soon as the file finishes downloading; execution order is not guaranteed. | Independent scripts that do not rely on another script running first. |
WordPress considers the dependency tree when applying a requested loading strategy, and may use a more conservative behavior to protect dependent scripts. Do not request async for code that depends on another script’s execution order. The strategy option is available from WordPress 6.3; on earlier versions, do not rely on that argument.
Add inline code to an enqueued asset
For a short configuration value or snippet that genuinely needs to be inline, enqueue its related asset first and attach the code to its handle. Use wp_add_inline_script() for JavaScript and wp_add_inline_style() for CSS. This keeps inline additions associated with the asset they support instead of making raw template output the default method for reusable code.
Best Value
Account for theme and build-system differences
Theme stylesheet metadata
A theme’s style.css remains required as the theme stylesheet and carries theme metadata. That requirement does not mean additional stylesheets should be hard-coded into templates; load additional front-end assets through the enqueue system.
Block themes and compiled assets
Block themes can load block-specific styles selectively rather than sending every style on every page. Build workflows may also generate dependency and version metadata alongside compiled files; use it to keep the enqueued asset’s dependencies and cache version aligned with the build output.
JavaScript modules
For WordPress 6.5 and later, wp_enqueue_script_module() is identified in the official function reference as the preferred way to enqueue script modules. This is for module-based code; ordinary classic scripts should continue to use wp_enqueue_script().
Choose scope before adding an asset
Decide whether an asset belongs on every front-end page, only in a particular condition, or only for a specific block or admin screen. Then declare its dependencies and required execution order, and confirm that the approach matches the site’s WordPress version and any build-generated asset metadata. Conditional loading is useful when code is needed in only one context; it should not be made global by default.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

