Home > Code, Google, PHP, Wordpress > WordPress Adsense – Ad Targeting Redirect

WordPress Adsense – Ad Targeting Redirect

When I was a Adsense n00b I made the mistake of adding adding a witty statement in my tagline in wordpress which confused adsense in terms of the content of my site, despite all the search engine optimization I had done . The symptom was: only the main index of my site had ads targeted solely on the wordpress “tagline” (the strip of text under the main title), all other pages on my site were targeted correctly. I thought this would be a matter of simply changing the tagline…but no, google doesn’t forget! I wont go into detail about the type of ads that were being targeted, lets just say they weren’t ideal.

A simple effective work around is a header redirect (permalink friendly) on the main site index which can be prefixed to the wordpress index.php in your wordpress top level directory.

<?php

// set $redirectHome = false to disable the redirect

$redirectHome = true;
if ($redirectHome){
        // Redirects index page
        $uriStr = $_SERVER['REQUEST_URI'];
        if (($uriStr == '/') || ($uriStr == '')){
                header('Location: /?index',true,301);
                die();
        }
        // Makes sure pages off the main index are not renamed 
        $matchAry = array();
        if (preg_match('/(\/page\/\d+\/)\?index/',$uriStr,$matchAry)){
                header('Location: ' . $matchAry[1],true,301);
                die();
        }
}

/**
 * Original WordPress index.php goes here
 */

This works because Google thinks “/?index” is a new page (it’s not though, it’s the main index with a query string attached) and the media bot crawls it and targets it accordingly as a new page. And as long as you’ve made your amendments to your previously incorrect content, in my case the “tagline” then this time around your ads should be accurately targeted…hopefully :)

The curious thing is, it seems no matter what only my original main index is targeted incorrectly still months later. I’ve seen other posts relating to incorrect ad targeting on the main index only. It seems like Google’s media crawler doesn’t like something about WordPress, I would like to hear from others that have experienced this.

  1. October 9th, 2009 at 08:07 | #1

    Great fix! I have been battling wordpress for weeks on this. After uploading numerous sites, and un-installing and re-installing I finally found this article. I also would like to thank you for providing easy to understand instructions as well as the code.

    I give your blog 2 thumbs and 2 big toes up!

  2. October 9th, 2009 at 19:08 | #2

    Cheers :)

    This particular problem did eventually come right, but we are talking about waiting months which is an unacceptable amount of time. This little hack worked fine while I was waiting for googles media-bot to recrawl the site index.

  3. November 6th, 2009 at 20:45 | #3

    Thanks for this. The exact same thing was happening to me, but the redirect seemed to work. What a pain, but I’m glad I was able to fix it! Good work!

  4. November 21st, 2009 at 19:15 | #4

    I’ve been searching for hours for a solution, thanks a million! I still can’t figure out why all of a sudden my ads became untargeted. My site has had relevant ads for over a year and then all of a sudden it’s showing body detoxification ads on a dog food site.

    Anyone have an idea why it would just randomly happen like this?

  1. No trackbacks yet.
*