is_customize_preview()
Checks whether the site is being previewed in the WordPress Customizer (the visual theme settings page). Conditional tag.
In basic request, the Customizer environment is newer loaded! This function only triggers (return true) when the Customizer environment is loaded — it means that:
- we are on the Customizer page (admin page),
- or we sent AJAX/POST/GET request to update our Customizer page,
- or we sent AJAX/POST/GET request to save Customizer options.
Uses global variable $wp_customize, which contains an instance of the WP_Customize_Manager class.
1 time — 0.000014 sec (very fast) | 50000 times — 0.01 sec (speed of light) | PHP 7.1.0, WP 4.7
No Hooks.
Return
true|false
. True if the site is being previewed in the Customizer, false otherwise.
Usage
is_customize_preview();
Examples
#1 Usage example
if( is_customize_preview() ){ // this is Customizer page }
#2 Php function for Customizer only
The function code will only be executed when we are on WordPress Customizer admin page.
function my_function(){ // exit if this is not Customizer if( ! is_customize_preview() ) return; // function code... }
Notes
- Global. WP_Customize_Manager. $wp_customize Customizer instance.
Changelog
Since 4.0.0 | Introduced. |
is_customize_preview() is customize preview code WP 6.7.1
function is_customize_preview() { global $wp_customize; return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview(); }