WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

<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 ?

share|improve this question
up vote 5 down vote accepted

Check for global variable $wp_customize:

if ( empty ( $GLOBALS['wp_customize'] ) ) 
    // show something

Update: in WordPress 4.0, you can use is_customize_preview().

share|improve this answer


global $wp_customize;
if (isset($wp_customize)) {
     // do stuff
share|improve this answer
This is actually the same way. – toscho Aug 29 '13 at 9:52
Not sure about downvotes. The answer is correct! Same as toscho but correct answer and cleaner. – Sisir Apr 29 '14 at 4:57

From Wordpress 4.0 you can use is_customize_preview();

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.