Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Load theme and plugin CSS and JavaScript with WordPress’s enqueue APIs, not hard-coded <link> or <script> tags. Enqueueing lets WordPress manage each asset by a unique handle, resolve dependencies, and print it in the right context. For assets used by a single block, prefer that block’s block.json metadata instead of loading them site-wide.

How WordPress asset enqueueing works

Enqueueing is a two-part process: register or enqueue an asset with a handle and its details, then let WordPress resolve dependencies and output the required tags. A handle is an identifier, not a filename; make it unique to your theme or plugin to reduce collisions. Dependencies should be other registered handles, not raw URLs.

For a theme, the standard front-end hook is wp_enqueue_scripts. WordPress’s Theme Handbook guide to including assets recommends enqueue APIs and theme-aware URL helpers rather than hard-coded asset markup or assumptions about a theme’s directory.

Enqueue front-end theme assets

Use theme helpers to build asset URLs. get_stylesheet_uri() returns the active theme’s stylesheet URL; get_theme_file_uri( 'assets/css/site.css' ) builds a URL for a file in the active theme, with child-theme override behavior; and get_parent_theme_file_uri( 'assets/css/site.css' ) explicitly points to the parent theme. When PHP needs a filesystem path rather than a URL, use the corresponding path helpers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

A basic front-end setup in a theme’s functions.php can look like this:

add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_assets' );

function mytheme_enqueue_assets() {
    wp_enqueue_style(
        'mytheme-site',
        get_theme_file_uri( 'assets/css/site.css' ),
        array(),
        '1.0.0'
    );

    wp_enqueue_script(
        'mytheme-site',
        get_theme_file_uri( 'assets/js/site.js' ),
        array(),
        '1.0.0',
        array( 'in_footer' => true )
    );
}

The style and script may use the same handle because WordPress tracks them separately, but distinct names such as mytheme-site-style and mytheme-site-script can make code easier to maintain. The script’s final argument shown here places it in the footer; consult the function reference for wp_enqueue_script() for the supported argument forms and behavior in your minimum WordPress version.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Enqueue plugin assets without assuming an installation path

Plugin assets should also be queued through WordPress APIs. Build their URLs with a portable helper such as plugins_url(), rather than assuming where WordPress or the plugin is installed. A typical pattern in a plugin PHP file is:

add_action( 'wp_enqueue_scripts', 'myplugin_enqueue_assets' );

function myplugin_enqueue_assets() {
    wp_enqueue_style(
        'myplugin-public',
        plugins_url( 'assets/css/public.css', __FILE__ ),
        array(),
        '1.0.0'
    );

    wp_enqueue_script(
        'myplugin-public',
        plugins_url( 'assets/js/public.js', __FILE__ ),
        array( 'jquery' ),
        '1.0.0',
        array( 'in_footer' => true )
    );
}

Keep dependencies accurate: include a dependency only when the code requires it, and use the handle under which that dependency is registered. The Plugin Handbook’s enqueuing guide covers plugin-side enqueueing and portable URL construction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Choose an asset scope that matches where it is used

Loading every stylesheet and script on every page is convenient, but unnecessary global assets add work to pages that do not need them. Pick the mechanism according to the asset’s owner and execution context:

Asset need Preferred approach Important qualification
Theme-wide public-facing styles or scripts Enqueue from wp_enqueue_scripts using theme URL helpers. Use a child-theme-aware helper when child themes should be able to override the file.
Plugin public-facing assets Enqueue through WordPress APIs and construct URLs with a helper such as plugins_url(). Use plugin-specific handles and declare required dependencies.
Assets required by one block Declare them in that block’s block.json metadata. Check the project’s minimum WordPress version because available metadata fields have evolved.
Assets for the editor interface generally Use enqueue_block_editor_assets with standard enqueue functions, or block metadata when the assets belong to one block. Editor iframe behavior and compatibility depend on WordPress version and setup.

Load block and editor assets in the right context

For an asset that belongs to a particular block, the Block Editor Handbook recommends the block.json workflow. Its metadata can describe editor scripts and styles as well as front-end scripts and styles. This keeps a block’s assets associated with the block instead of indiscriminately treating them as theme-wide or plugin-wide files. Consult the block metadata reference for available fields, and verify that each field is supported by the oldest WordPress version your project targets.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Editor-wide assets are different from assets needed by a block in both the editor and on the public site. The editor guide documents the enqueue_block_editor_assets hook for assets that belong in the editor interface. It also notes that editor iframe behavior and compatibility differ by version; see the editor asset guide, last updated July 24, 2026, when deciding where editor styles need to run.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Declare dependencies and choose a cache version

Dependencies tell WordPress which registered assets must be available before another script or style. For example, a script that calls jQuery should list the relevant registered handle as a dependency. WordPress uses handle and dependency information to organize output and ordering; an undeclared dependency can leave code running before a required library is present.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

The version argument helps browsers and intermediaries distinguish changed files from cached ones. For a manually maintained release, use a version that changes when the asset changes. The wp_enqueue_script() reference documents filemtime() as one possible script version value, which can invalidate the URL when a local file’s modification time changes. For a build pipeline, generated metadata can provide both dependencies and a content-derived version.

The Theme Handbook’s build process guide describes generated *.asset.php files that contain dependencies and a version. The dependency extraction package documentation explains how generated asset files can include a dependency list and a version hash based on bundle content, including extracted styles. Pass those generated values to the appropriate enqueue calls rather than maintaining a separate dependency list that can drift from the build.

Use defer or async only when the script and dependencies allow it

The script API documents loading strategies including defer and async. These strategy arguments are documented from WordPress 6.3, so do not assume they are available on older installations. The API considers the dependency tree when determining whether a requested strategy is eligible; a strategy is not simply a promise that every script will be emitted with the exact attribute requested. Review the script function reference and test behavior against the project’s supported WordPress versions, especially when scripts depend on one another.

A practical implementation checklist

  • Choose the correct context: public front end, editor interface, or both.
  • Prefer theme and plugin URL helpers over hard-coded directories or printed tags.
  • Use unique, prefixed handles and list required dependencies by handle.
  • Use block metadata for assets that are specific to a block, after checking minimum-version support.
  • Choose a versioning approach that fits the workflow: release version, generated content hash, or a file modification time where appropriate.
  • Use script loading strategies only when the target WordPress version supports them and the dependency behavior is suitable.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.