How to check if I am inside the WP Theme Customizer preview?

I have some elements showing on the home page that I do not want to display in the Theme Customizer preview window. Is there a simple check in PHP that I can use for that ?

For example:

Read More
<img class="background" src="<?php echo $background ?>" <?php if(is_wpThemeCustomizer()) echo 'style="display:none"' ?>/>

I could do it in javascript using the js file that is enqueued only in this case, but I would like to use PHP, or even better : CSS. Is it possible ?

Related posts

4 comments

  1. Alternatively

    global $wp_customize;
    if (isset($wp_customize)) {
         // do stuff
    }
    
  2. AS shared by iki, here is a simple example to add something conditionally, if currently on customizer preview page:

    if (is_customize_preview()) {
        // perform customizer specific action
    } else {
        // perform separate action
    }
    

Comments are closed.