WordPress 很多时候我们需要根据条件来选择不同的主题,比如手机端使用手机版主题,低版本 IE 使用可以兼容 IE 的主题等等,这些都需要通过 PHP 代码根据条件临时更换主题,下面的代码可以实现这一功能。
function Bing_phone_switching_theme(){
return 'Bing-Phone';
}
add_filter( 'template', 'Bing_phone_switching_theme' );
add_filter( 'stylesheet', 'Bing_phone_switching_theme' ); |
function Bing_phone_switching_theme(){
return 'Bing-Phone';
}
add_filter( 'template', 'Bing_phone_switching_theme' );
add_filter( 'stylesheet', 'Bing_phone_switching_theme' );
直接给两个 filter 返回主题目录名字即可实现代码更换主题,代码不执行的时候也就会使用手动选择的主题。
来源:
https://www.wpdaxue.com/switching-theme-filter.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32233.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57