繁体   English   中英

WordPress:如何通过脚本设置默认(活动)主题

[英]Wordpress: How to set default (active) theme via script

我需要通过脚本分配“活动”主题。 有人知道需要执行此API调用吗? 另外,如何通过脚本(PHP)检索当前主题?

更新current_theme选项:

update_option('current_theme', '[theme name]');

要获取主题名称,请使用:

$themes = get_themes();

在当前的Wordpress版本3.4.2中,您需要更新3个选项才能切换到另一个主题(在我的情况下为minihyper)

update_option('template', 'minihyper');
update_option('stylesheet', 'minihyper');
update_option('current_theme', 'Mini Hyper');

前两个选项是关键,第三个选项实际上什么也没做,只是您可以在代码中的某个位置使用此选项来显示当前主题名称。

更新:

这是一个真实的方法:

<?php switch_theme( $template, $stylesheet ) ?>

minihyper的示例:

<?php switch_theme( 'minihyper', 'minihyper' ) ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM