WordPress Multi (parked) Domains

You can find a few plugins to do this, but it really isn’t necessary .

You can simply add a couple of lines of code to your header template, as I have done on this site.

To see it in action, just try changing your “Location”  above……

This first bit of code can be put between the <head>   </head>

The code:

<?php global $title, $desc, $key;
$hosts = array( “saxon4u.com”,”saxon.im”,”saxons.us”);
$theurl = str_replace(“www.”,””,$_SERVER[‘HTTP_HOST’]);
$key = array_search($theurl, $hosts);
$title = array( get_bloginfo(),”Saxon For You “,”Saxon Int Media”,”Saxon Web USA”);
$desc = array( get_bloginfo(‘description’),”The Best Media Company “,”America’s Best”);

Explanation of the lines:

  1.  Declares Globals – so the variables can passed to all your pages and posts.
  2. Create an array of your domain names.
  3. Get the current domain name ( removing www if present ).
  4. Get the current domain name $key value.
  5. Create a title array  (I have set the first value as the default blog title).
  6. Create a description array (I have set the first value as the default blog description).

Now in the <body> just replace the title with:

<?php echo $title[$key]; ?>

and the description with:

<?php echo $desc[$key]; ?>

Now for the menu / navigation:

Just replace the <?php wp_list_pages(‘title_li=&depth=1’); ?> with:

$pages = get_pages(‘sort_column=menu_order’);
foreach ($pages as $pagg) {
 $paggg = get_page_link($pagg->ID);
 $addr = str_replace(get_option(‘home’), “http://”.$theurl, $paggg);
 echo “<li><a href=\”$addr\”>$pagg->post_title</a></li>”;
} ?>

You can add as many arrays as you like, but don’t forget to add them the the global (first line) if you want to use them throughout your website.