3
votes

I got situation like I am using multiple themes in my php website and also integrate a wordpress blog.

For example this is my site URL: http://example.com

There I want to switch Themes by passing a query parameter like:

http://example.com?mytheme=red_theme
http://example.com?mytheme=blue_theme
etc.

Currently my activated theme in WordPress is like blue_theme and my WordPress blog URL is like:

http://example.com/blog?mytheme=red_theme

e.g.: red_theme should be display just like preview.

Otherwise if I go through this URL:

http://example.com/blog

Then the default theme (blue_theme) should be display.

I can adjust it in core PHP but i don't know how to do it with WordPress.

1
Have you already looked for existing plugins here: wordpress.org/plugins/tags/theme-switcher ?dhh
Hi mevius, thank you for advise this wordpress function and I also tried out using that function and it works fine but this function is activate theme permanently I am looking for it should keep the theme temporary based on query string url. otherwise the default theme is activated previously...Priyank
@PriyankKhunt Maybe you can store the current/default theme name, then when a user accesses with a URL that doesn't contain a theme, reset to the one you have stored somewhere.ProfK

1 Answers

5
votes

In WORDPRESS, you can set Theme Programmatically, Based on Device, like different theme on mobile and different theme on Desktop. Write below code in functions.php of your Default theme

function use_mobile_theme() {
    // Chech device is mobile or not
    if(wp_is_mobile()){
        return 'theme19388'; // set theme name here, which you want to open on mobile
    }
    else {
        return 'milano'; // set theme name here, which you want to open on other devices, like desktop
    }
}

add_filter( 'stylesheet', 'use_mobile_theme' );
add_filter( 'template', 'use_mobile_theme' );