The Google Content Experiments installation is not working for me. I add the code in the header, but nothing is output.

So, I've added the Google Analytics experiment code manually into the header. The only problem is the theme is shared between network sites. So I want to only insert the code into the header on the condition that the current URL = {value}.

I know I can use conditional tags, but if I use is_page, this might fire accidently on another network site.

How do I do this?

global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
$is_specific_network = stripos( $current_url, 'specific_domain_or_ip_address' );
if( $is_specific_network !== false ) {
    // do the task below

} else {
    // do something else or leave it blank


N.B. : You need to replace the IP address or specific domain name above to distinguish the network.

=================== OR ======================

$current_site = get_current_site();
$current_domain = $current_site->domain;
if( $current_domain == 'something' ) {
    // do something

You can use anything from this data being returned:

An object containing details of the site currently being viewed. Details are represented in the following public variables: 

    (integer) ID of the site currently being viewed. 
    (string) Domain of the site currently being viewed. 
    (string) Path of the site currently being viewed. 
    (string) Title of the site currently being viewed.

Refer: http://codex.wordpress.org/WPMU_Functions/get_current_site

  • 1
    Beautiful. Note: I had to ensure I included the www. to ensure a match. – Steve Dec 9 '13 at 8:22
  • The Codex does not describe what path is. – Steve Dec 9 '13 at 8:23
  • 2
    Path provides you the absolute directory path for the setup. Like in *NIX : /var/www/... – Subharanjan Dec 9 '13 at 10:14
  • Unfortunately the Google Content Experiment code is being run on all pages of the website, as all pages have a match for the domain. – Steve Dec 12 '13 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.