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.

 

Share the post:Tweet about this on TwitterShare on Google+0Share on Facebook2Share on LinkedIn0

I’m a senior web developer helping clients build their websites to grow businesses. Currently I’m based in Taipei, Taiwan.

I write things about WordPress, AngularJS and life. Whenever you’d like to find someone to talk about these topics, just get in touch!

Submit a comment

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