Switch To Another Theme On Certain Pages In WordPress

I wrote a tiny WordPress plugin to switch themes between certain pages and the rest ones of a site. Check the gist out:

Here’s my brief explanation:

  1. Line 15-19: We need to hook to these two filters (stylesheet and template) to let WordPress know we’d like to use another theme other than the one has been set. I’d recommend we do such calls in setup_theme action. Maybe you could use other actions instead, if you find one, just let me know.
  2. Line 21-28: This is our filter function to change stylesheet WordPress would use. If you’re going to use a child theme like me, set your child theme here, or just use your theme.
    And the most important part is how I tell WordPress to switch themes on “certain pages”. I specify them by checking the $_SERVER['REQUEST_URI'] param.
  3. Line 30-37: Basically works like the previous one, just it changes the template (parent theme).

The use case of this plugin is that for a client site I built and maintain, I need to enable a survey form which will be built by Gravity Forms. Though it won’t be too difficult to build such form, I felt lazy to write some more CSS to style it. I was just wondering, it would be so much less work for me to do if I can use the default WordPress theme to display the form.

And after some googling, it’s done! I hope it could help you with your needs too.

 

One response

  1. Hello I would love to use your code. But I would love to speak to you about this.

    We would like

    Home by Theme A
    Custom Post Types to be served by Theme A
    Standard Blog Archive by Theme B
    Standard Blog Posts by Theme B
    A, B, C Products by Theme B
    X, Y, Z Products by Theme A
    Product Archive by Theme B
    D, E, F Specified Pages by Theme A
    G, H, I Specified Pages by Theme B

    I would really appreciate your help to do this because I don’t quite understand all the code

Leave a Reply

Your email address will not be published. Required fields are marked *