PHP code example of oberonlai / wp-asset

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

    

oberonlai / wp-asset example snippets




use ODS\Asset;

Asset::addScript();




use ODS\Asset;

add_action(
	'init',
	function() {
		Asset::addScript(
			array(
				'name'    => 'my_script',
				'url'     => YOUR_PLUGIN_URL . 'assets/js/script.js',
				'deps'    => array( 'jquery' ),
				'version' => YOUR_PLUGIN_VERSION,
				'footer'  => true,
				'ajax'    => false,
				'admin'   => false,
				'params'  => array()
			)
		)

		Asset::addStyle(
			array(
				'name'    => 'my_style',
				'url'     => YOUR_PLUGIN_URL . 'assets/css/style.css',
				'version' => YOUR_PLUGIN_VERSION,
				'deps'    => array(),
			)
		)
	}
);

Asset::addScript(
	array(
		'name'    => 'my_ajax',
		'url'     => YOUR_PLUGIN_URL . 'assets/js/ajax.js',
		'deps'    => array( 'jquery' ),
		'version' => YOUR_PLUGIN_VERSION,
		'footer'  => true,
		'ajax'    => true,
		'params'  => array(
			'data1'  => 'my_data_1',
			'data2'  => 'my_data_2',
		)
	)
)