最近在在帮小伙伴定制手机版公众号的内容,需要在手机版下另外定制一套主题,这里我们大致给一下思路。仅供参考
<?php
/*
Plugin Name: uzi_switch_theme
Plugin URI: https://uziwp.com/
Description: 用于uzi出品的主题切换插件
Version: 1.0.0
Author: Leo
Author URI: https://jiloc.com/
*/
if (!function_exists('uzi_mobile_switch_theme')) {
function uzi_mobile_switch_theme($theme)
{
if (wp_is_mobile()) {
$theme = 'uziwp_twentytwentytwo_mobile'; //theme为主题名
}
return $theme;
}
add_filter('template', 'uzi_mobile_switch_theme');
add_filter('stylesheet', 'uzi_mobile_switch_theme');
}
如果uziwp_mobile
是子主题,则不需要template钩子。
把以上代码贴到wp-content/plugins/uzi_switch_theme.php 中,在后台中启用即可。
评论已关闭