Wordpress: How to set default (active) theme via s

2019-06-12 03:24发布

I need to assign the "active" theme via script. Anyone know the API call needed to do this? Also, how do I retrieve the current theme via script (PHP)?

标签: php wordpress
2条回答
叼着烟拽天下
2楼-- · 2019-06-12 03:32

Update current_theme option:

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

To get the theme's name use:

$themes = get_themes();
查看更多
时光不老,我们不散
3楼-- · 2019-06-12 03:39

In current Wordpress version 3.4.2 you need to update 3 options to switch to another theme(minihyper - in my case)

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

The first two options are key, the third really does nothing except maybe you can use this option somewhere in code to display current theme name.

Update:

Here is a true way:

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

Example with minihyper:

<?php switch_theme( 'minihyper', 'minihyper' ) ?>
查看更多
登录 后发表回答