# Add Ads WP Plugin

**URL:** <https://forum.kirupa.com/t/add-ads-wp-plugin/186631>\
**Category:** open source\
**Created:** [April 23, 2006, 12:37am UTC](https://forum.kirupa.com/t/add-ads-wp-plugin/186631 "2006-04-23T00:37:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [April 23, 2006, 12:37am UTC](https://forum.kirupa.com/t/add-ads-wp-plugin/186631/1 "2006-04-23T00:37:58Z")

</div>

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
<?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]

---

<div class="post-metadata">

**Author:** ![MTsoul](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@MTsoul](https://forum.kirupa.com/u/MTsoul)\
**Post date:** [April 23, 2006, 12:42am UTC](https://forum.kirupa.com/t/add-ads-wp-plugin/186631/2 "2006-04-23T00:42:59Z")

</div>

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

Great job. Seems very useful.

---

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [April 23, 2006, 12:44am UTC](https://forum.kirupa.com/t/add-ads-wp-plugin/186631/3 "2006-04-23T00:44:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimhere](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jimhere/32/137_2.png) [@jimhere](https://forum.kirupa.com/u/jimhere)\
**Post date:** [April 23, 2006, 1:31am UTC](https://forum.kirupa.com/t/add-ads-wp-plugin/186631/4 "2006-04-23T01:31:26Z")

</div>

This is for WordPress (wp)?

---

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [April 23, 2006, 1:31am UTC](https://forum.kirupa.com/t/add-ads-wp-plugin/186631/5 "2006-04-23T01:31:43Z")

</div>

Yes.

---

<div class="post-metadata">

**Author:** ![LunaSolar](https://avatars.discourse-cdn.com/v4/letter/l/a4c791/32.png) [@LunaSolar](https://forum.kirupa.com/u/LunaSolar)\
**Post date:** [April 23, 2006, 1:41pm UTC](https://forum.kirupa.com/t/add-ads-wp-plugin/186631/6 "2006-04-23T13:41:52Z")

</div>

I love WordPress
