Php 如何在WordPress中以编程方式设置主题?
我得到的情况就像我在我的php网站中使用了多个主题,还集成了一个wordpress博客 例如,这是我的网站URL:Php 如何在WordPress中以编程方式设置主题?,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我得到的情况就像我在我的php网站中使用了多个主题,还集成了一个wordpress博客 例如,这是我的网站URL:http://example.com 在这里,我希望通过传递查询参数来切换主题,如: http://example.com?mytheme=red_theme http://example.com?mytheme=blue_theme etc. 目前我在WordPress中激活的主题类似于蓝色主题,我的WordPress博客URL类似于: http://example.com/bl
http://example.com
在这里,我希望通过传递查询参数来切换主题,如:
http://example.com?mytheme=red_theme
http://example.com?mytheme=blue_theme
etc.
目前我在WordPress中激活的主题类似于蓝色主题
,我的WordPress博客URL类似于:
http://example.com/blog?mytheme=red_theme
e、 g.:红色主题
应该像预览一样显示
否则,如果我通过此URL:
http://example.com/blog
然后应该显示默认主题(蓝色主题
)
我可以在核心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' );
…您是否已经在此处查找了现有插件:?嗨,mevius,感谢您提供此wordpress函数的建议,我也尝试过使用该函数,它工作正常,但此函数是永久激活主题,我正在查找它应根据查询字符串url暂时保留主题。否则,默认主题将在之前激活…@PriyankKhunt也许您可以存储当前/默认主题名称,然后当用户使用不包含主题的URL访问时,重置为您存储在某处的URL。