1. Go to this page and download the library: Download dimadin/commonwp 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/ */
dimadin / commonwp example snippets
add_action( 'wp_enqueue_scripts', function() {
// Use the .min version if SCRIPT_DEBUG is turned off.
$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_enqueue_script( 'popper.js', get_template_directory_uri() . "/assets/js/popper{$min}.js", [], '1.14.0', true );
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . "/assets/js/bootstrap{$min}.js", [ 'jquery', 'popper.js' ], '4.1.0', true );
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . "/assets/css/bootstrap{$min}.css", [], '4.1.0' );
} );
add_filter( 'npm_packages_scripts', function( $scripts ) {
// For file: https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js
$scripts['bootstrap'] = [ // This is the handle used when script is registered in WordPress.
'package' => 'bootstrap', // Slug of npm package.
'file' => 'dist/js/bootstrap', // Path to file, excluding extension (it is always either .js or .css).
'minified' => '.min', // If file has both minified and unminified version, and if simple suffix can be added to the base.
];
// For file: https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js
$scripts['popper.js'] = [
'package' => 'popper.js',
'file' => 'dist/umd/popper',
'minified' => '.min',
]
return $scripts;
} );
add_filter( 'npm_packages_styles', function( $styles ) {
// For file: https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css
$styles['bootstrap'] = [
'package' => 'bootstrap',
'file' => 'dist/css/bootstrap',
'minified' => '.min',
];
return $styles;
} );