Post Pic

Force the use of a specific WordPress theme

Did you know that in WordPress, the $theme variable control the apparence of your blog? In fact, its value is the name of your theme. In this recipe, I’m going to show you how you can switch themes using a simple code snippet.

Just paste the following code in the functions.php file. When this code will be executed, the "default" theme will replace your current theme.

add_filter('option_template', 'dontchoose');
add_filter('template', 'dontchoose');
add_filter('option_template', 'dontchoose');
add_filter('option_stylesheet', 'dontchoose');

function dontchoose($theme) {
	$theme = 'default';
	return $theme;
}

This recipe was inspired by Nathan Rice's code to Serve IE6 Visitors the Default WordPress Theme, make sure to check it out too!

6 Responses

Sep 17 2009 17:45

I checked out the link to Nathan Rice’s code and I like the idea of forcing IE to go to a different more basic theme thereby encouraging them to upgrade their browser, but I can’t see a reason to just add the above code.

It is early and I haven’t had much caffeine this morning but that code would force all users to see the default theme. I must be missing something. Someone please enlighten me.

Sep 17 2009 19:08

1. The first line of you code is a duplicate of line 3.
2. You have to use this code in a plugin. Doing it in a theme’s functions.php file has unintended consequences like partially loading templates from the active theme and the theme you specify.

Nathan

Sep 17 2009 19:58

I actually went to Nathan’s site and read more about this cool trick. It’s actually pretty neat and useful solution for IE6 issues. Thanks for sharing this idea over here guys!

Sep 21 2009 09:57

I was thinking… And I found a nice use for it. Sometimes some part of websites are so different that we can just create separate themes and use this hook to serve the desired them in each page.
I’ll try it soon. TY

Oct 01 2009 17:10

Nice found. i will use it when i will have problems with theme activations :)

Jan 17 2010 00:43

Thank you very much, this workaround solved a probleme with my whole wordpres blog!

I was uploading a new theme using fireftp and dreamweaver when suddenly wordpres crached to the blank screen od death as they call it, but your fix helped me to change the theme and re upload it again and it works now.

thanx

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required