Title: Example for domain based logic?
Last modified: December 5, 2018

---

# Example for domain based logic?

 *  Resolved [iparker](https://wordpress.org/support/users/iparker/)
 * (@iparker)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/example-for-domain-based-logic/)
 * Hello,
 * can you give me a simple example how to build domain based logic?
 * For example
 * if(domain == a)
    echo ‘XXX’; elseif(domain == b) echo ‘YYY’;
 * How can I use the MULTPLE_DOMAIN_DOMAIN-constant? Can I differ in content of 
   a site/post using any kind of shortcode?
 * Or/and can you give a small code example how to writer a filter/function which
   handles something like this?
 * Thanks for some help!
 * Best regards,
 * Timo

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Contributor [Gustavo Straube](https://wordpress.org/support/users/gustavostraube/)
 * (@gustavostraube)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/example-for-domain-based-logic/#post-10949179)
 * Hello Timo,
 * There are two constants available:
    - `MULTPLE_DOMAIN_DOMAIN` – the current domain the user is browsing
    - `MULTPLE_DOMAIN_ORIGINAL_DOMAIN` – the original domain, where your WP is installed
 * You can use those constants to write any logic in your theme. Something like 
   this in your `header.php`:
 *     ```
       <?php if (MULTPLE_DOMAIN_DOMAIN === 'mycoolblog.com') : ?>
       <h1>Welcome to my cool blog</h1>
       <?php endif; ?>
       ```
   
 * If you want to check if the user is visiting any page that’s not your original
   domain:
 *     ```
       <?php if (MULTPLE_DOMAIN_DOMAIN !== MULTPLE_DOMAIN_ORIGINAL_DOMAIN) : ?>
       <p>Thanks for visiting my other domain!</p>
       <?php endif; ?>
       ```
   
 * Sure, these are dumb examples but I think you can get the idea from them.
 * You can also use those constants inside a filter or an action.
    -  This reply was modified 7 years, 6 months ago by [Gustavo Straube](https://wordpress.org/support/users/gustavostraube/).
 *  Thread Starter [iparker](https://wordpress.org/support/users/iparker/)
 * (@iparker)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/example-for-domain-based-logic/#post-10965114)
 * Hi Gustavo,
 * great – thanks for this example. This helped me and worked fine!
 * Best regards,
 * Timo
 *  Thread Starter [iparker](https://wordpress.org/support/users/iparker/)
 * (@iparker)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/example-for-domain-based-logic/#post-11071918)
 * Hello Gustavo,
 * I have an additional question about this topic: Is it possible to output the 
   MULTPLE_DOMAIN_DOMAIN-value in a shortcode (or something like a shortcode)?
 * I want to have a text-output with a dynamic naming of a domain in it.
 * Thanks for some help with this!
 * Best regards,
 * Timo
 *  Thread Starter [iparker](https://wordpress.org/support/users/iparker/)
 * (@iparker)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/example-for-domain-based-logic/#post-11098440)
 * Hello,
 * I found a solution with the creation of a shortcode for this:
 * function domain_shortcode(){
    return MULTPLE_DOMAIN_DOMAIN; } add_shortcode(‘
   domainShortcode’, ‘domain_shortcode’ );
 * Best regards,
 * Timo
 *  Plugin Contributor [Gustavo Straube](https://wordpress.org/support/users/gustavostraube/)
 * (@gustavostraube)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/example-for-domain-based-logic/#post-11099966)
 * Hey Timo,
 * Could you give me details on why you needed this? Maybe I can add it to the plugin
   codebase as a new feature. I wanted to know more to make it more flexible, if
   possible.
 * Cheers!
 *  Thread Starter [iparker](https://wordpress.org/support/users/iparker/)
 * (@iparker)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/example-for-domain-based-logic/#post-11100046)
 * Hi Gustavo,
 * I just wanted to output the domain in a text dynamically, for example
 * “MULTPLE_DOMAIN_DOMAIN” is a service for xyz
 * Hope you understand what I mean ;-).
 * Best regards,
 * Timo
 *  Plugin Contributor [Gustavo Straube](https://wordpress.org/support/users/gustavostraube/)
 * (@gustavostraube)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/example-for-domain-based-logic/#post-11105566)
 * Timo,
 * The latest update (v 0.8.5) now has a built-in shortcode. It’s called “[multiple_domain]”.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Example for domain based logic?’ is closed to new replies.

 * ![](https://ps.w.org/multiple-domain/assets/icon-256x256.png?rev=2502840)
 * [Multiple Domain](https://wordpress.org/plugins/multiple-domain/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/multiple-domain/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/multiple-domain/)
 * [Active Topics](https://wordpress.org/support/plugin/multiple-domain/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/multiple-domain/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/multiple-domain/reviews/)

## Tags

 * [constants](https://wordpress.org/support/topic-tag/constants/)

 * 7 replies
 * 2 participants
 * Last reply from: [Gustavo Straube](https://wordpress.org/support/users/gustavostraube/)
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/example-for-domain-based-logic/#post-11105566)
 * Status: resolved