How to get the URL for a WordPress site

How do you fetch the URL for a WordPress site?

The problem

My wife has started a new business focusing on the Swedish healthcare market. With the main company website up and running, she then aquired two more websites with fairly different domain names. Neither of which can be found through a simple search for select keywords on Google.

These websites featured the same, identical content. The reason for the identical content where that the domain names where essentially synonyms (equivalent words) for a specific profession. The idea where to drive traffic to either site and have them serve useful information for the profession in question (such as average salary for the last three years etc). Now, Google doesn’t look kindly on duplicate content (as some of you web savvy people already know). Duplicate content can make a website suffer greatly when it comes to search results; Heck the site might not turn up at all! That is very bad news for a small company trying to make its presence known on the world wide web.

The solution for this problem was to either do a 301 redirect or make use of a Canonical url’s. There is a lot of information to be read on the internet about when to use 301 redirect and when not, or when to use Canonical url’s instead. In essence a 301 redirect tells the search engines that a page has permanently moved to a new address; Thus the search engine will remove the old address/page from the index and from thereon pass visitors and credit to the new page. A canonical url simply states that there is multiple versions of this page (~ duplicate content). A canonical url then goes on to specifically point out the master version. The master version is the only version that will be indexed by and get any credit from search engines. All other versions is still available through favorites/bookmarks or surfing to them directly through making use of the address bar in the web browser; However, they are not indexed.

As my wife wanted both websites available, as she have marketed them both, there was but one choice really. I had to make use of Canonical url’s. Now, fortunately, one of the websites recieved considerable more traffic than the other. Making rounds with different SEO tools confirmed that the keyword for that domain was more popular. I needed then not to worry about deciding which site should point to the other. What I needed to do was simply to point to the more popular domain from the lesser so. But as there is quite a few pages and a search function to consider – it wasn’t all quick and easy. All the pages had to be pointed to the equivalent pages on the more popular site etc. Hence, it is not enough just to point to the base URL (ie. The URL in the canonical link needs to be absolute, not relative. Thus I needed to get all parts of the URL including the search query string (if available). Heres how a canonical link should look like:

<link rel="canonical" href="">

The solution

What follows is a simple PHP example snippet that could be used to write out the canonical url (it needs to be placed after the HEAD in the html code). Use it cautiously as canonical links can backfire if wrongly used!


// Base URL, ie.
$url_base = $_SERVER['SERVER_NAME'];

// Last part after the base URL without query string 
// variables
$url_part = add_query_arg(array(),$wp->request); 

// Last part after the base URL with query string 
$url_partandquery = $_SERVER['REQUEST_URI'];

// Full URL including query string variables
$url_full = $url_base."".$url_partandquery;

// WordPress search function command
$url_searchterm = get_search_query();

// Print out the first part of the canonical url

  echo '<link rel="canonical" href=';

// What page are the user viewing? 

if ($url_part == "") {
  // The $url_part is empty meaning that the user is 
  // viewing the frontpage or is searching for 
  // something. Lets find out what.

  if (!strpos($url_full, '?')) {

    // No query string thus the user is viewing the 
    // frontpage. Lets print out the canonical url.

    echo '"http://'.$url_base.'">';

  } else {
    // The user is searching for something. Lets found 
    // out what. Then print out the canonical url.

    echo '"http://'.$url_base.'/s='.$url_searchterm.'">';

} else {

  // The $url_part contains something - Thus the user is 
  // viewing an individual news post 

  echo '"http://'.$url_base.'/'.$url_part.'/">';

Sonicterror Recordings Remix Music Competition/Compo

I typically write news in swedish for the most part. But this time it concerns a music compo announced by  Sonicterror Recordings.

I saw the announcement on social media and thought that it would be fun to take part in it. So, late saturday night, the 4th of November (coincidentally on my sons 8th birthday), I started working on a remix for the competition.

A remix of what song you might ask yourself. Well, End.user’s track Between. A cracking breakcore tune. A genre which is far from the stuff that we usually compose/produce (we’re mostly into Swedish Pop/dance).

Anyway, 24h later we had a remix finished that we thought was decent. Now, we could have gone to extreme lengths and perfected it technically in all ways possible etc; Since the deadline for the competition isn’t until friday the 24th of November. But the overall feeling was that it was good enough. Hence we uploaded the remix to Soundcloud and then we mailed the organizers of the compo.

Interested in listening to the remix? Well, here it is

If you would like to download the source file for the DAW (ie. software used to create the remix), then here it is


We have used Renoise 3.1 (as the DAW) to compose the remix


Sergio Kun Agüero

Sergio Kun Agüero

Det är ju inte var dag man får skåda fotbollshistoria skapas såsom det gjordes denna tisdagskväll när Manchester City mötte Napoli på bortaplan (Sau Paulo Stadium) i Champions League. Med sitt första mål för matchen gjorde Sergio Kun Agüero 3-2 målet. I och med detta mål passerade han Eric Brook som klubbens bästa målgörare med 178 st mål totalt. Grymt imponerande. Mer imponerande är att han slår rekordet med långt färre matcher spelade än Eric (264 framträdanden mot 494 st för den senare).

Matchen gick inte av för hackor heller. 4-2 vart slutresultatet med City som vinnare.