现在我正在尝试切换Wordpress使用的模板,具体取决于正在查看网站的设备。
这里的确切问题是,似乎要切换的唯一事情是脚本和样式表。他们自己的实际模板(索引,页眉,页脚)保持不变。
以下是我用来执行此操作的功能:
<?
function fxn_change_theme($device) {
$header = $_SERVER['HTTP_X_UA_DEVICE'];
if ($header === 'mobile') {
$theme = 'jankness-mobile';
} elseif ($header === 'tablet') {
$theme = 'jankness-tablet';
} else {
$theme = 'jankness-desktop';
}
return $theme;
}
add_filter('template', 'fxn_change_theme');
add_filter('option_template', 'fxn_change_theme');
add_filter('option_stylesheet', 'fxn_change_theme');
?>
此外,唯一正在执行任何操作的过滤器似乎是“模板”,选项过滤器不会做太多。我试着查看他们做了什么,目前我还不清楚。
这可能是什么问题?
答案 0 :(得分:0)
Basically, since the code I was using was sitting in functions.php it was not able to manipulate the theme content earlier enough in the Wordpress core process. So the solution was to move the code into a very simple plugin exactly as it is, and hook in to the theme_setup point using the same code I used here.