do_action( 'customize_preview_init', WP_Customize_Manager $manager )
Fires once the Customizer preview has initialized and JavaScript settings have been printed.
Parameters
-
$manager
WP_Customize_Manager -
WP_Customize_Manager instance.
More Information
This action hook allows you to enqueue assets (such as javascript files) directly in the Theme Customizer only. To output saved settings onto your live site, you still need to output generated CSS using the wp_head hook.
Generally, this hook is used almost exclusively to enqueue a theme-customizer.js file for controlling live previews in WordPress’s Theme Customizer.
For more information, see the Theme Handbook article on the Theme_Customization_API.
Source
File: wp-includes/class-wp-customize-manager.php
.
View all references
do_action( 'customize_preview_init', $this );
Changelog
Version | Description |
---|---|
3.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example migrated from Codex:
Usage might look like this…
Example migrated from Codex:
Example Javascript Handler
The following is one example of what a Javascript live preview file might look like for a custom implementation of the Theme Customizer…
The contents of your theme-customizer.js file might look like this:
As you can see from the example above, a single basic handler looks like this…
Note:
Keep in mind that the above will only work if you have set all referenced
SETTINGS
to ‘transport
‘=>’postMessage
‘. By default, WordPress uses ‘transport
‘=>’refresh
‘ for all settings (including the ones that are built in). You can override those defaults using the customize_register action hook.When using the theme customizer’s live preview, this is an example of how to enqueue scripts.