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.
I think you could use the ?preview=true in the url something like :
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’sstart_previewing_theme
andstop_previewing_theme
hooked from theWP_Customize_Manager
class in/wp-includes/class-wp-customize-manager.php
andsetup_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 intheme.php
ispreview_theme
; hopefully one or a combination of these hooks will give you what you want.