You can manually add AdSense in a WordPress post above or below the content without any issue. You can simply place the necessary code above, or below, the the_content(); function call. Now if you want to place it within the content, it is a bit more complex.
Most people would install a plugin that will automatically insert your AdSense code into the content of any post. I have used them in the past, but found that it would break the post readability if the code was inserted into the wrong location. Also, some people wish to reduce the number of plugins that are activated in the blog, so a manual method may be better. Once the code is added manually, you can easily monitor your AdSense coverage.
Manually Add AdSense in a WordPress Post Without a Plugin

In order to place AdSense in your post without a plugin, you would need to edit the single.php file in your theme. You will then replace the the_content(); function call with the code below.
Code to Manually Add AdSense in a WordPress Post
$show_after_p = 1;
$content = apply_filters('the_content', $post->post_content);
if(substr_count($content, '<p>') > $show_after_p)
{
$contents = explode("</p>", $content);
$p_count = 1;
foreach($contents as $content)
{
echo $content;
if($p_count == $show_after_p)
{
?>
<!-- Insert code here -->
<?php
}
echo "</p>";
$p_count++;
}
}
?>
I should note, however, that the code isn’t mine because I found it online (if someone knows the source, please let me know so I can give proper credit). Basically, you would insert your AdSense code by replacing this line:
After doing that, you can then choose to display the AdSense ads after a specific paragraph by indicating a paragraph number in the following line:
While this code only allows you to add AdSense after one paragraph, if you know PHP, then you can modify the code to allow multiple AdSense code insertions.
The above code allows you to manually add AdSense in a WordPress post content so you don’t need to use an additional plugin.





on November 5, 2010 at 4:13 pm
Knowing how to do little php fixes like that – it’s gold! And if you dont’ use a plugin, it doesn’t slow down your blog either. Good stuff!
Barbara Ling, Virtual Coach recently posted…Which lurking reader is helping YOUR blog score the perfect touchdown
on November 5, 2010 at 8:03 pm
Until I started this blog I never programmed in PHP before. Performing tasks without the use of a plugin, and learning WordPress in general has helped me learn PHP at the same time.
on November 8, 2010 at 1:04 pm
Thanks for the great tutorial. I am using another simple way to add Adsense code, that’s the Quick Adsense plugin. I only need to install the plugin, setup ad codes and then insert some codes like to anywhere in my posts.
Tuan recently posted…The Stablest URL Shortener on the Web
on November 9, 2010 at 3:24 pm
I have used such plugins, but I am not a fan of inserting codes in my posts. This is because I may want to change where they are located, and don’t want to go through all the posts to change the code placement.
on November 17, 2010 at 1:06 pm
And it will showing your ads code after first paragraph.
Android recently posted…Samsung Drops Galaxy Tab Prices In the UK But Still More Than AT&T
on November 20, 2010 at 12:54 pm
Nice tutorial.will try that
on November 29, 2010 at 3:31 pm
This is a great tip, Paul. Anytime code can easily be used instead of a WP plugin is a big plus, IMO.
Twitter: WindowsTalk
on November 30, 2010 at 8:09 am
I agree. I try to limit the number of plugins that I use, especially the ones that I can code manually into my template. There are several plugins that do come in handy, such as SEO and backup plugins.
on December 2, 2010 at 3:08 am
hmmm..interesting. i wonder if this would work on a ning blog..thanks
on December 2, 2010 at 8:13 am
I’m not familiar with ning, but if it is PHP based it may work as most of the code is standard PHP. You would have to substitute any WordPress functions, though.
on December 8, 2010 at 8:32 am
For me I use a plugin called Quick Adsense. It is really easy to use without using and codings… You should try it out
Kharim Tomlinson recently posted…How To Deal With Negative Listings In Search Engines
on December 8, 2010 at 9:19 am
Thanks, I may look at Quick AdSense, but I find it easier to edit the template manually. I guess I am a hands-on type of guy.
on December 9, 2010 at 1:51 am
Hi Paul – it’s possible you got your inspiration from this article?
http://www.dollarshower.com/how-to-blend-your-adsense-block-within-the-wordpress-post-content-conditionally-display-it/
Either way, this is a great code snippet.
Cheers!
_Khalid
Khalid J Hosein recently posted…Download Firefox to Treat Red Pandas
on December 9, 2010 at 8:08 am
The article had good instructions, but I don’t think it was that one. While the code is similar, I remember the article I read actually had text instead of images.
on December 10, 2010 at 1:08 am
Gotchya.
By the way, do you know if your code works when the article is paged, i.e. when you use the WordPress operator to break it out into multiple pages?
Thanks!
on April 11, 2011 at 7:53 pm
i think it would work if in your post you assign …. in every single post.. it would be unconfortable..
I just think using simple code plugin.. U can found at http://www.aming.info/increase-the-google-page-ctr-by-adsense-rotator-in-php/
http://www.aming.info/adsense-injection-plugin-in-single-post/
http://www.aming.info/smowtion-ensemble-of-ads-wordpress-plugin/
on May 12, 2011 at 6:36 am
tips of use indeed for those who are not that fluent with wordpress code customisations.
Chandan recently posted…Problem with earning money online without investment in India
on August 17, 2011 at 12:19 pm
Thanks man,
i’ll use it for my blog.