I wanted that when i access my site with specific parameter, my site used a different theme at that moment (only temporarily, to show only to me as a preview). I want it for test purposes. Is there any way to do/activate that using php codes?


You can Detect Server Remote Address and if it matches with your IP then you can use different theme following way.

function wp_set_preview_theme( $current_theme ) {
        // Use your preview theme instead
        return 'THEME_YOU_WANT_TO_USE';
    } else {
        // Otherwise, keep the current theme
        return $current_theme;

add_filter( 'stylesheet', 'wp_set_preview_theme' );
add_filter( 'template', 'wp_set_preview_theme' );
  • add_filter( 'template' not worked in functions.php Template not changed. But in plugin file this is work.
    – Alexufo
    Jul 18 '17 at 16:02

For styling and layout testing, the best and easiest option is to use the customizer which lets you change themes, set changes while viewing the site, and you just do not apply the changes in the end if you still not at the point of actually switching themes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.