• Resolved Kerzzy

    (@kerzzy)


    Hi everyone,
    I have a big problem with subdomains in WordPress, I have searched and I haven’t found any answer.
    I want to create a website that have a domain, for example domain.com.
    Then I would like to have three subdomains, product1, product2 and product3.domain.com.
    The domain will have everything (it will show all the products) and the subdomains will have exactly the same content as the domain, except the other products (for example in the menu, a product section in the domain with the products, and for product 1, only product 1).
    I realised that domain/subdomains were completely separated. So now I think about one question; is that possible ? If yes, I can easily code with php and I’m not really searching for a plugin.

    (Subdomain was a choice that I found better than subfolders, because they enhance the product’s view.)

    Any help is welcome (:

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Possible yes.

    No one has yet built that plugin though.

    Thread Starter Kerzzy

    (@kerzzy)

    Thank you, I will try to do this.

    Kerzzy – I would be interested in your solution. I have a similar situation – a main company domain that displays all/most of the content – and then each location has its own domain but only displays content specific to its location.

    Thread Starter Kerzzy

    (@kerzzy)

    I’ve got a solution within StackOverFlow :

    Yes, multisite is not what you need here. I would try to map all subdomains on the same wordpress install, and then customize the template via the current URL. In the wp-config.php you then use the current URL as base url:

    define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
    define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);

    You can also do different themes per subdomain (see plugins for “theme switcher”).

    After that I found the way to get the current subdomain into a variable :
    $subdomain = array_shift((explode(".", $_SERVER['HTTP_HOST'])));
    Then you use it in your child theme or your own theme.

    I hope it can help ^^

    love your solution – having trouble with the conditional statement in my theme though, could you post a sample?

    instead of language i need to deliver different tracking codes, logos etc based on subdomain.

    Thanks in advance!

    Thread Starter Kerzzy

    (@kerzzy)

    Hi builtbypeter,
    you simply need to use it like this (example for a different logo in each sub/domain) :

    $subdomain = array_shift((explode(".", $_SERVER['HTTP_HOST'])));
    if($subdomain == 'sub1'){ // https://sub1.domain.com/
      $image_url = '/img/logo1.png';
    }elseif($subdomain == 'sub2'){
      $image_url = '/img/logo2.png';
    }elseif($subdomain == 'domain'){ // https://domain.com/
      $image_url = '/img/main-logo.png';
    }
    
    echo '<img src="'.$image_url.'" alt="Logo" />;'

    And you use it in your templates, or in functions.php using hooks.

    I hope it answered your question ^^

    Best regards,
    Kerzzy

    It definitely helps thank you, I actually like your syntax much more than mine —
    ———————–

    if ( ‘test1.fmgsuite.com’ === $_SERVER[‘HTTP_HOST’] )
    echo “G’Day buddy!
    “;

    ———————–

    Not sure if this is the correct route for me to take yet to achieve my end result, but the nuts and bolts are definitely in place now. Can’t thank you enough! Press on!

    Kerzzy – what template and where would you plant that code?

    Thread Starter Kerzzy

    (@kerzzy)

    Hi ekingstad,

    Wherever you need it in your theme (in PHP), see Page Templates, or like explained in the example before, in functions.php with hooks :

    $sub = array_shift((explode(".",$_SERVER['HTTP_HOST']))); // Global var
    
    /**
    * Function to change the menu according to the subdomain
    */
    add_filter( 'wp_nav_menu_args', 'my_primary_menu_args' );
    function my_primary_menu_args( $args ) {
    	global $sub;
    	if($sub == 'www')
    		$args['menu'] = 'Main menu'; // Created in Appearance > Menus
    	else
    		$args['menu'] = 'Secondary menu';
    	}
    	return $args;
    }

    Regards,
    Kerzzy

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Subdomains that have almost same content as the domain’ is closed to new replies.