简体   繁体   English

WordPress主题取决于域名

[英]Wordpress theme depends on domain

How to show different themes on wordpress site depending on site domain? 如何根据站点域在wordpress网站上显示不同的主题? All content the same on all domains/themes. 所有内容在所有域/主题上均相同。
Is it possible? 可能吗? If so, can you recommend the solution? 如果是这样,您可以推荐解决方案吗?

Example: 例:
1. site1.com - theme1. 1. site1.com-theme1。
2. site2.com - theme2. 2. site2.com-theme2。
3. same content. 3.相同的内容。

Try creating a custom Must-Use plugin to use the switch_theme( $stylesheet ) function. 尝试创建一个自定义的必备插件,以使用switch_theme( $stylesheet )函数。

<?php

add_filter( 'template', 'wpse_49223_change_theme' );
add_filter( 'option_template', 'wpse_49223_change_theme' );
add_filter( 'option_stylesheet', 'wpse_49223_change_theme' );
function wpse_49223_change_theme( $theme )
{
    $domain = $_SERVER['SERVER_NAME'];
    $domain = str_replace('www.', '', $domain);
    if ( $domain == 'site2.com' )
        $theme = 'theme2';
    else
        $theme = 'theme1';

    return $theme;
}

Based on this solution at WordPress StackExchange. 基于WordPress StackExchange上的解决方案。

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

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