如何在WordPress中以编程方式设置主题?

我遇到的情况就像我在php网站中使用多个主题, 并且还集成了一个wordpress博客。

例如, 这是我的网站URL:http://example.com

我想通过传递查询参数来切换主题:

http://example.com?mytheme=red_theme
http://example.com?mytheme=blue_theme
etc.

目前, 我在WordPress中激活的主题就像blue_theme, 而我的WordPress博客URL是:

http://example.com/blog?mytheme=red_theme

例如:red_theme应该像预览一样显示。

否则, 如果我通过以下URL:

http://example.com/blog

然后, 应显示默认主题(blue_theme)。

我可以在核心PHP中对其进行调整, 但我不知道如何使用WordPress。


#1


在WORDPRESS中, 你可以基于设备以编程方式设置主题, 例如移动设备上的不同主题和桌面上的不同主题。在默认主题的functions.php中编写以下代码

function use_mobile_theme() {
    // Chech device is mobile or not
    if(wp_is_mobile()){
        return 'theme19388'; // set theme name here, which you want to open on mobile
    }
    else {
        return 'milano'; // set theme name here, which you want to open on other devices, like desktop
    }
}

add_filter( 'stylesheet', 'use_mobile_theme' );
add_filter( 'template', 'use_mobile_theme' );

来源:

https://www.srcmini02.com/63488.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_37611.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?