Help with adsense code in wordpress

craigjarvis

Registered Member
Joined
Nov 19, 2009
Messages
80
Reaction score
10
I have a code setup in my index.php to insert my ad into the first post of the page only with this code
<?php the_content(__('(more...)')); ?>
<?php if ($count == 1) : ?>
<script type="text/javascript"><!--
google_ad_client = "pub-*************";
/* 300x250, created 7/15/10 */
google_ad_slot = "5671363641";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

How do I change it to cause ads to be inserted into the first 3 posts?

Thanks for your help.
 
It would be a lot easier and more flexible if you used a plugin instead of hard coding your index file. There are lots of free ones available for adsense ad placement. Try this one:

Code:
http://wordpress.org/extend/plugins/quick-adsense/

I have a code setup in my index.php to insert my ad into the first post of the page only with this code
<?php the_content(__('(more...)')); ?>
<?php if ($count == 1) : ?>
<script type="text/javascript"><!--
google_ad_client = "pub-*************";
/* 300x250, created 7/15/10 */
google_ad_slot = "5671363641";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

How do I change it to cause ads to be inserted into the first 3 posts?

Thanks for your help.
 
Yeah, just G00gle quick adsense wordpress plugin, pretty self explanatory, you can insert adsense wherever you want (beginning of the post/page, middle, end etc). You can also use widget "Arbitrary text or HTML" to have a nice wide (160x600) skyscraper in your sidebar.
 
I thought about using a plugin, but Ive had them mess up my site code once, and insert someone elses adsense codes into my site once so Id rather code it. Just cant figure out what to change in the code. I copied the code from another site....
 
What theme and what version of WordPress are you using? Without knowing that, here is what i'd try.

I have all my WordPress sites set to display the entire post instead of excerpts so I dont have any "more" links .. but from what you posted it looks like they set the index file to search the posts for
Code:
<?php the_content(__('(more...)')); ?>
and just hard coded the adsense block between the end of the excerpt and above the "more" link on the first post with
Code:
<?php if ($count == 1) : ?>
So it seems like you should be able to just re use the same code over twice more changing ($count == 1) to ($count == 2) and ($count == 3) . ( I don't see any point in coding a loop since you are only allowed 3 adsense blocks)

I thought about using a plugin, but Ive had them mess up my site code once, and insert someone elses adsense codes into my site once so Id rather code it. Just cant figure out what to change in the code. I copied the code from another site....
 
Thanks for the tips. Can you show me how you get the full content and no ecxerps? I use an rss feed from google news.

BTW im usuing 2.92 I believe, and an iphone 4 theme i found.
 
You can use the Easy Adsense Plugin, just search for it on Google, this plugin works great and its very easy to use!
 
Back
Top