A hook that runs only when the theme is previewed

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.

Read More

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

Related posts

Leave a Reply

2 comments

  1. 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.