Add Ads WP Plugin

Way too much of a mess for me, but I am using it anyways on my site. It’ll add an ad to only the first post on the page (actually, it’ll add the text ‘<GOOGLE_AD>’ to the end of the post. Then, it’ll start output buffering in the head of the document, and replace all instances of ‘<GOOGLE_AD>’ with the actual contents of the ad. That way, you can add that string anywhere in your code, and it’ll be replaced. Should be pretty simple to understand.

<?php
/*
Plugin Name: Add Ads
Description: Add the Google Ads to the content.
Version: 0.1
Author: Jeff Wheeler
Author URI: http://www.nokrev.com/
*/

function addAdsCallback($buffer)
{
	$ad = <<<GOOGLE_AD
<script type="text/javascript"><!--
google_ad_client = "pub-*****************";
google_alternate_color = "ffffff";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="";
google_color_border = "EEEEEE";
google_color_bg = "FFFFFF";
google_color_link = "60A6BC";
google_color_url = "47899E";
google_color_text = "999999";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
GOOGLE_AD;

  return (str_replace('<GOOGLE_AD>', $ad, $buffer));
}

function addAdsToContent ($content) {
	static $totalContentAds = 0;

	if ($totalContentAds==0) {
		$content.='<GOOGLE_AD>';
		$totalContentAds++;
	}
	
	return $content;
}

function start_ob() {
    ob_start('addAdsCallback');
}

add_filter('the_content','addAdsToContent');
add_action('wp_head', 'start_ob');

?>

[whisper]I’m also posting this on my site…[/whisper]

I’m guessing if I start using that code you’ll get money? :stuck_out_tongue:

Great job. Seems very useful.

Nah. I took out my Adsense publisher id. Notice all the *****… ah shoot. I pasted my code a second time and forgot to take it out! Fixing.

Edit: Fixed.

This is for WordPress (wp)?

Yes.

I love WordPress