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

Is there a function or a hook that runs only when a theme is previewed?

I'm referring to the preview feature that you get on the Appearance->Themes page.

The reason for this is that I want to change specific design aspects on the theme but only when the user is previewing it.

share|improve this question
Have you searched a database? – Raphael Jan 26 '12 at 19:30

I think you could use the ?preview=true in the url something like :

if ($GET['preview']) {
// your hook or function
share|improve this answer

When I ask myself questions like this, I usually find that the UNIX find command, combined with Adam Brown's Wordpress Hooks site gives me some pointers.

When sitting in a WordPress root, running find . -name '*.php' | xargs grep -i preview | grep -i action shows that there's 3 hooks that might be useful, although you'd need to experiment a bit. There's start_previewing_theme and stop_previewing_theme hooked from theWP_Customize_Manager class in /wp-includes/class-wp-customize-manager.php and setup_theme hooked from /wp-includes/theme.php.

Cross-checking Adam's WordPress Hooks site also shows up these hooks; http://adambrown.info/p/wp_hooks/hook/start_previewing_theme, http://adambrown.info/p/wp_hooks/hook/stop_previewing_theme and http://adambrown.info/p/wp_hooks/hook/setup_theme.

The setup_theme hooks is also interesting as the hook handler in theme.php is preview_theme; hopefully one or a combination of these hooks will give you what you want.

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.