[wp-hackers] Switching theme depending time of the year

Otto otto at ottodestruct.com
Wed Dec 28 16:53:22 UTC 2011


On Wed, Dec 28, 2011 at 9:11 AM, Kirk Wight <kwight at kwight.ca> wrote:
> I think it can be even simpler than everything mentioned so far - add the
> date class to the body_class function, and make your appropriate stylesheet
> changes: http://codex.wordpress.org/Function_Reference/body_class

It can even be simpler than that. Switching themes entirely based on
some set of conditions is easy.

add_filter('template','date_switch_theme');
function date_switch_theme($theme) {
	$month = date('n');
	if ($month >= 1 && $month <= 4) return 'themename-1';
	if ($month >= 5 && $month <= 8) return 'themename-2';
	if ($month >= 9 && $month <= 12) return 'themename-3';
	return $theme; // shouldn't happen
}

Obviously, you'll want to manually activate these themes and configure
them individually before using code like this to switch between them.

-Otto


More information about the wp-hackers mailing list