1. Go to this page and download the library: Download themehybrid/hybrid-assets library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Hybrid\Assets\Plugin as AssetsPlugin;
$this->app->singleton( 'my-plugin/assets', static function ( $app ) {
/** @var AssetsPlugin $plugin */
$plugin = $app->make( AssetsPlugin::class );
$plugin->setPluginFile( MY_PLUGIN_FILE );
// By default, plugin asset overrides are expected under `{theme}/public/my-plugin/...`.
// Themes can override this slug to match their own asset structure, such as `dist/`,
// `assets/`, or any other custom directory.
$plugin->setOverrideAssetsDirectory(
apply_filters( 'my-plugin/assets/override/path', '/public/my-plugin' )
);
return $plugin;
} );
/** @var \Hybrid\Assets\Asset $asset */
$asset = Assets::asset( 'js/my-file.js', true );
wp_register_script(
'my-file',
$asset->url(),
$asset->dependencies(), // read from js/my-file.asset.php, if present
$asset->version(), // from .asset.php, mix-manifest.json, or a content hash
true
);
// Checks the child theme first, then falls back to the parent theme itself.
Assets::asset( 'js/my-file.js', true );
// For a plugin: checks child theme, then parent theme (both under the
// plugin's override directory), before falling back to the plugin's own file.
Assets::asset( 'js/my-file.js', true );