您可以只检查customize对象,但如果您确实需要一个条件语句来确定您需要的内容,则可以执行以下操作:
jQuery( function( $ ) {
// set var
var in_customizer = false;
// check for wp.customize return boolean
if ( typeof wp !== \'undefined\' ) {
in_customizer = typeof wp.customize !== \'undefined\' ? true : false;
}
// if you\'re in the customizer do this
if ( in_customizer ) {
console.log(\'in customizer\');
// if you\'re not in the customizer do this
} else {
console.log(\'not in customizer\');
}
});