Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#23509 closed enhancement (fixed)

Conditional function that lets you know if your site is being viewed through the Customizer

Reported by: nathanrice's profile nathanrice Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.0 Priority: normal
Severity: normal Version:
Component: Customize Keywords: has-patch
Focuses: template Cc:


I can provide a use case if necessary, but this should be relatively simple.

If I need to do something special with my theme when my site is being viewed through the customizer, there's no easy way determine if it is.

A simple is_customizer() (or similar) function would be incredibly useful in this scenario.

I'd write up a patch, but I don't know where to put the new function.

Attachments (2)

23509.diff (561 bytes) - added by sammybeats 11 years ago.
23509-refreshed.diff (523 bytes) - added by mattwiebe 11 years ago.

Download all attachments as: .zip

Change History (19)

#1 @SergeyBiryukov
11 years ago

  • Component changed from Themes to Appearance

This seems to work for me:

global $wp_customize;
if ( isset( $wp_customize ) ) {
	// ...

11 years ago

#2 @sammybeats
11 years ago

  • Cc sammybeats added
  • Keywords has-patch needs-testing added

Submitted a patch that creates a function is_customizer() that checks to make sure $wp_customize is of type WP_Customize_Manager and returns the value of $wp_customize->is_preview();

#3 @ethitter
11 years ago

  • Cc erick@… added

#4 @philiparthurmoore
11 years ago

  • Cc philip@… added

#6 @ScottSmith
11 years ago

Is it possible to push for this to be added to the WordPress 3.7 milestone?

#7 @mattwiebe
11 years ago

  • Cc matt@… added

I've refreshed and simplified the patch. We've been running this on since April and we should land it in 3.8.

#8 @dgwyer
11 years ago

  • Cc d.v.gwyer@… added

#9 in reply to: ↑ description @ocean90
10 years ago

  • Focuses template added
  • Keywords reporter-feedback added; 2nd-opinion needs-testing removed

Replying to nathanrice:

I can provide a use case if necessary

Can you please?

#10 @nathanrice
10 years ago

mattwiebe mentioned that they're using this on He can probably provide a much more compelling use-case than I could.

#11 @mattwiebe
10 years ago

Here's some use cases from

  • Custom Fonts in the Customizer - we use a Typekit kit on a non-Customizer view, but all font rendering happens via a preview script in the Customizer. We use is_customizer() to decide which should be enqueued.
  • Stylesheet concatenation - turn off in the Customizer for Custom CSS users so that we can identify the specific stylesheet and remove it when the user edits their stylesheet.
  • don't load stats scripts in the customizer

There's a few more that aren't as easy to explain.

#12 follow-up: @ocean90
10 years ago

  • Keywords reporter-feedback removed
  • Milestone changed from Awaiting Review to 4.0

Thanks mattwiebe.

is_customizer seems like a fine name, but isn't it more is_customize_preview?

#13 in reply to: ↑ 12 @mattwiebe
10 years ago

Replying to ocean90:

Thanks mattwiebe.

is_customizer seems like a fine name, but isn't it more is_customize_preview?

Both have some ambiguity. I've always thought is_previewing bit of the Customizer seems a bit weird when you're not previewing a non-active theme, at least not at first.

I actually think in_customizer is a bit clearer but most of our conditionals go with is_*.

#14 @obenland
10 years ago

Keep in mind we also have is_preview() for post previews.

#15 @celloexpressions
10 years ago

I would suggest either is_customize, is_customizing or is_customize_preview. It's the customize preview in the sense that you're previewing the changes you're making to different settings, regardless of whether or not it's a theme preview.

In code, everything's customize, not customizer. However, considering the customizer as the thing and customize as the action, is_customizing could also make sense. But is_customize_preview is probably our best option here, all things considered.

This ticket was mentioned in IRC in #wordpress-dev by SergeyBiryukov. View the logs.

10 years ago

#17 @SergeyBiryukov
10 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 28999:

Add is_customize_preview(), a conditional function to check if the site is being previewed in the Customizer.

props sammybeats, mattwiebe.
fixes #23509.

Note: See TracTickets for help on using tickets.