WordPress.org

Ready to get started?Download WordPress

Plugin Directory

WP Customizer

Easily load site specific functions, scripts and CSS files into your site without editing your theme's functions.php or other source files.

Filter Support And Usage

WP Customizer supports multiple filters; the plugin's filters allow you to

  • modify the set of functions files that are about to be loaded
  • modify the set of script files that are about to be loaded
  • modify the characteristics of each script file that is about to be loaded and which will be passed as arguments to wp_enqueue_script
  • modify the set of CSS files that are about to be loaded
  • modify the characteristics of each CSS file that is about to be loaded and which will be passed as arguments to 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.

wp_customizer_functions, wp_customizer_admin_functions, wp_customizer_common_functions

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();
}

wp_customizer_scripts, wp_customizer_admin_scripts, wp_customizer_common_scripts

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;
}

wp_customizer_css, wp_customizer_admin_css, wp_customizer_common_css

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;
}

Requires: 3.5 or higher
Compatible up to: 3.6.1
Last Updated: 2013-9-18
Downloads: 1,737

Ratings

5 stars
5 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.