WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] My solution to multiple domains (6 posts)

  1. sninad
    Member
    Posted 2 years ago #

    I perused the postings in this section for days and came up with this solution to multiple domains with custom image headers for each. Comments and questions are encouraged.

    My client is using a child theme of purple-pastels for multiple domains relating to tutoring in many communities in the San Francisco Bay Area. Her main domain is http://tutordoctorsanfrancisco.com and she has add-on domains such as http://tutoringinsausalito.com, http://tutoringinberkeley.com, etc. Each add-on domain has its own installation of WordPress 3.3.1 and they all share the same database and the same content. Using bits and pieces from other posts in this section, I came up with a solution to have a custom header image for each domain. Note, however, some of the domains do actually share the same header image.

    The solution I chose was to modify wp-config.php for each domain to contain something like the following code:

    define('WP_SITEURL', 'http://tutoringinsausalito.com');
    define('WP_HOME', 'http://tutoringinsausalito.com');
    define('CUSTOM_IMAGE_HEADER', 'http://tutoringinsausalito.com/wp-content/uploads/header4.png');

    Then I modified functions.php in the purple-pastels theme to look for CUSTOM_IMAGE_HEADER and use it if it is present:

    if (defined('CUSTOM_IMAGE_HEADER')) echo '#headimg {background-image:url("' . CUSTOM_IMAGE_HEADER . '");}';
    	else if( get_header_image() != '' ) echo '#headimg {background-image:url(' . get_header_image() . ');}';
    	else echo '#headimg {background-image:none;}';

    I probably should check for the existence of the image header, but I got lazy.

    The custom image header defined in wp-config.php gets displayed properly and because of the setting of WP_SITEURL and WP_HOME, the user stays on the domain they have chosen, for example, http://tutoringinoakland.com.

    I am an experienced software engineer with decades of experience and I have been working with WordPress for about six months.

    I would appreciate comments and insights about the approach I have taken to solve my client's desires. Please let me know what you think! I am especially interested in how closely this follows what an experienced WordPress developer might have done. I had considered posting a question in this forum, but decided to get my feet wet.

    Thanks,

    [sig moderated as per the Forum Rules]

  2. sunrayshining
    Member
    Posted 2 years ago #

    Hi,

    I'm relatively new to WP and not a programmer. Have basic knowledge of HTML and php.

    I've got a main domain http://www.seedmedia.co.za and sub-domain http://www.seedcorporatemedia.co.za

    Intially I took the MU plugin route, but since I want to modify the look of the sub domain, decided to try having separate instals of wp and separate databases. Trouble is that when try wp-login to the sub-domain, it rejects password and kicks me to wp-login of main domain.

    I tried your modification above, but no help.

    What would you recommend?

    Thanks in advance,
    Warren

  3. Make your own topic please :)

    If you're using multiple installs, however, you're not using Multisite. We would suggest using Multisite and then a domain mapping plugin.

  4. design.bradford
    Member
    Posted 2 years ago #

    Excellent solution, @sninad! I only used the 'SITE_URL' and 'SITE_HOME' portions, but they worked like a charm.

    Designing a mobile theme to be used strictly on webkit mobile devices(so desktop users are redirected to the about site), but still needed to set up a mirror site to load as a demo on the 'About this project/theme' site, this worked perfectly!

  5. Ruben.cc
    Member
    Posted 2 years ago #

    I came here looking for a solution to a slightly different problem, but I felt like replying to this one anyway.

    If I understand correctly, you want to have different header images on different domains using the same database (and therefore probably the same theme?)

    Why not just modify the header of the theme and use the php command $_SERVER['HTTP_HOST'] to get the name of the domain that is called? Than use that for an image name, like...

    <?php
    $image=$_SERVER['HTTP_HOST'].".jpg";
    echo "<img src='".$image."' />";
    ?>

    Then simply put images on the server called
    tutordoctorsanfrancisco.com.jpg
    tutoringinsausalito.com.jpg
    tutoringinberkeley.com.jpg

    Or am I totally misunderstanding the problem/solution here, in which case; sorry! :-)

  6. Ruben.cc
    Member
    Posted 2 years ago #

    ...or even shorter...

    <?php
    echo "<img src='".$_SERVER['HTTP_HOST'].".jpg' />";
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic