最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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 ?

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 asked Jun 3, 2013 at 15:23 Fabien QuatravauxFabien Quatravaux 1,7031 gold badge14 silver badges29 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 6

Check for global variable $wp_customize:

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

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

Alternatively

global $wp_customize;
if (isset($wp_customize)) {
     // do stuff
}

From Wordpress 4.0 you can use is_customize_preview();

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
}
发布评论

评论列表(0)

  1. 暂无评论