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:
- Line 15-19: We need to hook to these two filters (
stylesheet
andtemplate
) 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 insetup_theme
action. Maybe you could use other actions instead, if you find one, just let me know. - 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. - 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.
Leave a Reply