Matching Google Ads

So you want your Google Ads to match the rest of your page, but you have a style switcher. All of the sudden your green colored ads (that match your green style) don’t match the pretty pink style. See the problem? You may have noticed that my Ads change with the style. Here’s how I did it…

Yes, I know it’s not an elegant solution, but it works. Since you are using a style switcher, there is a cookie being used. We’ll use this same cookie to display particular ad colors and settings. Create a PHP file for the Google Ads…I call mine google-banner.php. Here’s my file with explanations of particular parts:

<?php

//Specific items used for the “rustic” style

$rustic = <<<RUSTIC

google_color_border = “cc6633″;

google_color_link = “993300″;

google_color_url = “993300″;

RUSTIC;

//Specific items used for the “gangreen” style

$gangreen = <<<GANGREEN

google_color_border = “339966″;

google_color_link = “006600″;

google_color_url = “006600″;

GANGREEN;

//Specific items used for the “blueprint” style

$blueprint = <<<BLUEPRINT

google_color_border = “333399″;

google_color_link = “000066″;

google_color_url = “000066″;

BLUEPRINT;

//This is the top portion of the ad code which will be used

//for each ad style, remember to place your client ID inside

//the quotes for google_ad_client

$adtop = <<<ADTOP

<script type=”text/javascript”><!–

google_ad_client = “”;

google_ad_width = 468;

google_ad_height = 60;

google_ad_format = “468x60_as”;

google_ad_channel =””;

google_color_bg = “ffffff”;

google_color_text = “000000″;

ADTOP;

//…And stuff used for the bottom of each ad.

$adbot = <<<ADBOT

//–>

<script type=”text/javascript” src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”&gt;

</script>

ADBOT;

echo $adtop; //Output the top of the ad

//Check the cookie and output the appropriate “stylized” ad code

switch($_COOKIE["wpstyle"]) {

//If your style cookie is named something different, replace “wpstyle”

case ‘blueprint’ :

echo $blueprint;

break;

case ‘gangreen’ :

echo $gangreen;

break;

default :

echo $rustic;

break;

}

echo $adbot; //Output the bottom of the ad

?>

Modify everwhere in the code that the names of my styles (rustic, gangreen, blueprint) are used and enter the names of your styles.

Now just include this file in your PHP pages where you want the ads to appear. Modify the path and filename to match your setup.

<?php include “/home/blahblah/username/html/google-banner.php”; ?>

This can be customized quite a bit by passing more of the google variables to each style instead of including them with the $adtop or $adbot. Depending on your styles, you could position your ads in different places on the page, use a tower in one style and a banner in another. I can’t wait to see what people come up with.

One thought on “Matching Google Ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s