我遇到的情况是我在我的 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 进行调整。
最佳答案
在 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' );
关于php - 如何在 WordPress 中以编程方式设置主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30796038/