PHP code example of nyco / wp-assets

1. Go to this page and download the library: Download nyco/wp-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/ */

    

nyco / wp-assets example snippets


use NYCO\WpAssets as WpAssets;

$WpAssets = new WpAssets();

// The general pattern for all methods is $WpAssets->{{ method }}()
$WpAssets->addScript();

wp_register_script('main', '/wp-content/themes/theme/assets/js/main.831f1593.js', [], null, true);
wp_enqueue_script('main');

$WpAssets->addScript('main');

$GLOBALS['wp_assets']->addScript();

NYCO\WpAssets

->addScript( ...args )

$WpAssets->addScript();

$WpAssets->addScript('main');

add_filter('script_loader_tag', function($tag, $handle) {
  if ($handle === 'main') {
    // do something to $tag like add attributes, disable for certain views, etc.
  }

  return $tag;
});

->addStyle( ...args )

$WpAssets->addStyle();

$WpAssets->addStyle('site');

->addAttr( ...args )

$WpAssets->addAttr('script', 'async', true);

->loadIntegrations( ...args )

$integrations = $WpAssets->loadIntegrations();

->addInline( ...args )

$integrations = $WpAssets->loadIntegrations();

if ($integrations) {
  $index = array_search('google-analytics', array_column($integrations, 'handle'));

  $WpAssets->addInline($integrations[$index]);
}

define('GOOGLE_ANALYTICS', 'GTM-9A9A9A9');

->registerRestRoutes( ...args )

add_action('wp_enqueue_scripts', function() {
  enqueue_inline('google-analytics');
});
shell
$ mv wp-content/mu-plugins/wp-assets/autoloader-sample.php wp-content/mu-plugins/wp-assets.php
shell
$ mv wp-content/mu-plugins/wp-assets/integrations-options.php wp-content/mu-plugins/wp-assets-integrations.php