Dynamically change Wordpress Theme

ぐ巨炮叔叔 提交于 2019-12-04 07:14:34

问题


How can I set an a tag to dynamically change the theme currently being displayed by wordpress?

I understand the switch function as described in a similar question here: Display page content using multiple templates - WordPress , but I don't know how to implement the change. Should the switch be added to index.php inside a theme, or inside the theme folder? Does my link point to the index.php file?

I would like to do this without a plugin if possible.

An example of a site which does this already: www.envye.com/wordpress/

Thank you!


回答1:


Use this in function.php

function fxn_change_theme($theme) {

  if( $condition == true )
    $theme = 'twentytwelve';
  else
    $theme = 'twentyteleven';

  return $theme;
}

add_filter('template', 'fxn_change_theme');
add_filter('option_template', 'fxn_change_theme');
add_filter('option_stylesheet', 'fxn_change_theme');



回答2:


You can use the switch_theme() method. https://codex.wordpress.org/Function_Reference/switch_theme



来源:https://stackoverflow.com/questions/24766911/dynamically-change-wordpress-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!