简体   繁体   中英

Wordpress theme different URL

I have 2 domains sharing the same Wordpress theme. I don't want to manage 2 separate themes, but there are a few small differences in the sites. I want to do something similar to the:

<?php if ( is_page( 'Contact' )) { ?>
  <!-- Contact content -->
<?php } else { ?>
  <!-- Other content -->
<?php } ?>

But instead of looking for a page, it is looking for a different full URL: Such as http://example.com versus http://example.net .

You can try this:

<?php if ( $_SERVER['HTTP_HOST'] == 'example.net' ) : ?>
    <div> Example.net</div>
<?php else : ?>
    <div> Example.com</div>
<?php endif; ?>

Or if you want to use regex:

<?php if ( preg_match('/\.example.net/', $_SERVER['HTTP_HOST']) ) : ?>
    <div> Example.net</div>
<?php else : ?>
    <div> Example.com</div>
<?php endif; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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