Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress] "/about/", "/news/", "/blog/" というURLにアクセスした時にテーマを切り替える
<?php
/*
Plugin Name: Hardcode theme switcher
Plugin URI: http://ja.forums.wordpress.org/topic/13483
Author: Takuro Hishikawa
Version: 0.1
*/
function my_theme_switcher($theme){
// yes, it's hardcoded!
switch (preg_replace('#^/([^/]+)/?.*$#', '$1', $_SERVER['REQUEST_URI'])) {
case 'about':
$overrideTheme = 'twentyten';
break;
case 'news':
$overrideTheme = 'twentyeleven';
break;
case 'blog':
$overrideTheme = 'twentytwelve';
break;
default:
$overrideTheme = false;
}
if ( $overrideTheme ) {
$overrideTheme = wp_get_theme($overrideTheme);
return $overrideTheme->exists()
? $overrideTheme['Template']
: $theme;
}
return $theme;
}
add_filter('stylesheet', 'my_theme_switcher', 50);
add_filter('template', 'my_theme_switcher', 50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.