• Resolved iparker

    (@iparker)


    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

    (@gustavostraube)

    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.

    Thread Starter iparker

    (@iparker)

    Hi Gustavo,

    great – thanks for this example. This helped me and worked fine!

    Best regards,

    Timo

    Thread Starter iparker

    (@iparker)

    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

    (@iparker)

    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

    (@gustavostraube)

    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

    (@iparker)

    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

    (@gustavostraube)

    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.