We'll create fresh WordPress site with WP Customizer installed. You have 20 minutes to test the plugin after that site we'll be deleted.
This plugin allows you to manage and load site specific functions, scripts and CSS files into your WordPress site without the need to edit your theme’s functions.php
or any other source file.
Settings and options include:
WP Customizer supports multiple filters; the plugin’s filters allow you to
wp_enqueue_script
wp_enqueue_style
Each filter will be only be called if the customization type is enabled in the plugin’s options; if a customization type is enabled but no files are found to be loaded, the filter will still be called but will be passed an empty argument.
As with all WordPress filters, any filter hook function should either return the modified argument or the original argument if no modification were made.
The functions filters are called when preparing to load the list of front-end functions (wp_customizer_functions
), of admin functions (wp_customizer_admin_functions
) and of common functions (wp_customizer_common_functions
). The arguments that each filter hook function receives is identical in all cases. The filter hook function takes a single argument which is an array of file names.
Example: Prevent all function files from loading by returning an empty file list.
add_filter('wp_customizer_functions', 'function_handler', 10, 1);
function function_handler($files) {
// $files = array(
// array(
// 'file' => (absolute path of function file)
// ),
// array(...)
// );
return array();
}
The scripts filters are called when preparing to load the list of front-end scripts (wp_customizer_scripts
), of admin scripts (wp_customizer_admin_scripts
) and of common scripts (wp_customizer_common_scripts
). The arguments that each filter hook function receives is identical in all cases. The filter hook function takes a single argument which is an array of file details.
Example: Add jQuery as a dependency to all scripts and enable each script to load in the post’s footer.
add_filter('wp_customizer_scripts', 'script_handler', 10, 1);
function script_handler($files) {
// $files = array(
// array(
// 'file' => (absolute path of script file),
// 'handle' => (auto-generated handle for script),
// 'src' => (URL of script file),
// 'deps' => (dependencies, defaults to an empty array),
// 'ver' => (version, defaults to false),
// 'in_footer' => (load in footer, defaults to false),
// ),
// array(...)
// );
foreach ($files as $file) {
$file['deps'] = array('jquery');
$file['in_footer'] = true;
}
return $files;
}
The CSS filters are called when preparing to load the list of front-end CSS (wp_customizer_css
), of admin CSS (wp_customizer_admin_css
) and of common CSS (wp_customizer_common_css
). The arguments that each filter hook function receives is identical in all cases. The filter hook function takes a single argument which is an array of file details.
Example: Override the media type for all CSS files to use the screen
media type.
add_filter('wp_customizer_css', 'css_handler', 10, 1);
function css_handler($files) {
// $files = array(
// array(
// 'file' => (absolute path of css file),
// 'handle' => (auto-generated handle for CSS),
// 'src' => (URL of CSS file),
// 'deps' => (dependencies, defaults to an empty array),
// 'ver' => (version, defaults to false),
// 'media' => (media type, defaults to 'all')
// ),
// array(...)
// );
foreach ($files as $file) {
$file['media'] = 'screen';
}
return $files;
}