• Resolved spok72

    (@spok72)


    This plugin is a great solution.
    What code to use to switch between two templates?

    • This topic was modified 4 years, 2 months ago by spok72.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    You can use the stylesheet filter to change the active child theme:

    add_filter( 'stylesheet', function ( $theme ) {
    	return 'twentytwelve';
    } );

    If you would like to change the active parent theme, you need to use the template filter as well:

    $theme_callback = function ( $theme ) {
    	return 'twentytwelve';
    };
    
    add_filter( 'stylesheet', $theme_callback );
    add_filter( 'template', $theme_callback );
    Thread Starter spok72

    (@spok72)

    thank you very much for your quick reply. I will hook this code and check if it works.

    Regards

    Thread Starter spok72

    (@spok72)

    Works but only temporarily. When I click on any link, after passing back the old template.
    The change is not permanent within the page being viewed

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi @spok72,

    If you’d like a more permanent change, then you can use the switch_theme function.

    Keep in mind that this function has a permanent effect, so you don’t need to run it on every page load. You could use it in an only run once snippet, or have some sort of check for when you want to use it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘switch theme’ is closed to new replies.