Documentation

Assets
in package

AbstractYes

Assets Registration class.

Provides a method for the batch registration of assets using a declarative array structure. This abstract class serves as a foundation for managing asset dependencies, versions, and inclusion conditions across different parts of a WordPress site.

Tags
since
1.0.0

Table of Contents

Methods

set()  : void
Registers multiple assets in bulk.

Methods

set()

Registers multiple assets in bulk.

public static set([array<string|int, mixed> $assets = [] ]) : void

This method allows for the efficient registration of multiple assets by accepting an array of asset definitions. Each asset definition is an associative array that specifies the properties of the asset, such as its handle, source URL, dependencies, version, and other relevant attributes for stylesheets and scripts.

Example usage:

Assets::set([
    [
        'handle'  => 'main-style',
        'src'     => mix('css/style.css'), // Assumes `mix` is a function that resolves asset paths.
        'deps'    => [],
        'version' => '1.0.0',
        'media'   => 'all', // For stylesheets only.
        'hook'    => 'wp_enqueue_scripts',
    ],
    [
        'handle'    => 'main-script',
        'src'       => mix('js/app.js'),
        'deps'      => [],
        'version'   => '1.0.0',
        'in_footer' => true, // For scripts only. Determines where the script is loaded.
        'hook'      => 'wp_enqueue_scripts',
    ],
]);
Parameters
$assets : array<string|int, mixed> = []

An array of asset definitions. Each definition is an associative array that includes 'handle', 'src', 'deps', 'version', and optionally 'media' for styles, and 'in_footer' for scripts, among others.

Tags
link

to more detailed documentation or examples]

since
1.0.0

        
On this page

Search results