How to Insert AdSense Codes Inside Post ?


A few weeks ago, one of my visitors asks me about how to insert the Google AdSense ads (advertisements) in the middle (inside) a post. Previously, I’m using manual methods for adding the AdSense ads inside a post. But, after some research, I’ll try to implement some coding to make AdSense ads (advertisements) inside a single post automatically.

Implementation
As I’ve been told before, this tricks only applied for Single Page template or any page that displaying full articles. Here’s how:

Open your Single Post Template (usually at single.php)
Find out this code inside your template:

Change the above code with this code:

<?php
$where = 4;
$content = apply_filters(’the_content’, get_the_content());
$content = explode(”</p>”, $content);
for ($i = 0; $i
if ($i == $where) { ?>

//Your AdSense / Advertisement codes

<?php
}
echo $content[$i] . “</p>”;
}
?>

Save the template and see the result.

2nd line is a variable to determine the paragraph that you want the code to be inserted. The important thing you have to know, since index PHP is started from 0, then the value of “$where = 4;“ in the above code means the 5th paragraph ($where + 1)
To implement the AdSense ads or other advertisements, you can locate it at the 8th line. The result can be seen here:

insert adsense

For publishers or webmaster who wants some modification, the codes can be altered to make it suitable inside any site. The alternate codes to implement the AdSense (advertisements) ads are:

To place the ads at the left side, change the 7th – 9th line to:
<div style=”float:left; margin:0 10px 10px 0;”>
// Your AdSense / Advertisement codes
</div>

To place the ads at the right side, change the 7th – 9th line to:
<div style=”float:right; margin:0 0 10px 10px;”>
// Your AdSense / Advertisement codes
</div>

To place the ads at the center area, change the 7th – 9th line to:
<div style=”text-align:center; margin:10px 0;”>
// Your AdSense / Advertisement codes
</div>

To make the ads always at the most bottom paragraph, change the 2nd – 4th line to:
$content = apply_filters(’the_content’, get_the_content());
$content = explode(”</p>”, $content);
$where = count($content)-1;

To randomize the ads placement, change the 2nd – 4th line to:
$content = apply_filters(’the_content’, get_the_content());
$content = explode(”</p>”, $content);
$where = count($content)-1;
$where = rand(min, count($content)-2);

Note: min = the minimum paragraph will be used, change it! (1st paragraph = 0)


Tags: , , , , , , , , , , ,


Bloom in ADSENSE, AFFILIATE, GOOGLE, SEO PAGERANK |
Monday, June 18th, 2007
Related Post:
How to Insert Multiple AdSense Inside Post?
Wrap Adsense Inside Post
How to Make Submit Links to Social Bookmarks?
Search Engine Optimization
Make Auction Pages with AuctionAds

4 Responses to “How to Insert AdSense Codes Inside Post ?”

  1. Advertiser Watch » Blog Archive » How to Insert AdSense Codes Inside Post ? Says:

    […] angellica2017 Filed in […]

  2. عبدالرحمن Says:

    thanks alot

  3. Bryce Beattie Says:

    weird, mine erased it, too
    I’ll try it this way
    for ($i = 0; $i<count($content); $i++){
    \

  4. How to Insert AdSense Codes Inside Post ? » {webmaster} : Webmaster Inspirations - Web Design, SEO, Software, Internet, Technology, Cheat, Guide by Cloyd Says:

    […] Save the template and see the result. […]

Leave message (spam will be banned) :

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>