首页 文章

动态更改Wordpress主题

提问于
浏览
-1

如何设置一个标签来动态更改wordpress当前显示的主题?

我理解这里类似问题中描述的切换功能:Display page content using multiple templates - WordPress,但我不知道如何实现更改 . 应该将开关添加到主题内的index.php,还是主题文件夹中?我的链接指向index.php文件吗?

如果可能的话,我想在没有插件的情况下这样做 .

已经执行此操作的网站示例:www.envye.com/wordpress/

谢谢!

2 回答

  • 1

    在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');
    
  • 0

    您可以使用 switch_theme() 方法 . https://codex.wordpress.org/Function_Reference/switch_theme

相关问题