Posts Tagged ‘header redirect’

WordPress Adsense – Ad Targeting Redirect

August 20th, 2009 4 comments

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.


// 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);
        // 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);

 * 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.