Go Back   WarriorForum - Internet Marketing Forums > The Warrior Forum > Adsense / PPC / SEO Discussion Forum
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 11-22-2010, 02:51 AM   #1
Warrior Member
 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to insert Adsense Code in the Middle of a Post?

Hello all,

Does anyone know of a way to insert Adsense code in the middle of a long Wordpress post? Assuming posts are usually >450 words and are of variable length.

There's already an Adsense placement at the top and bottom of each post. I thought it'll be good to add one in the middle as well.

Tried adding 160X600 at the sidebar but clickthrough is pathetically low.

Thanks for any advice.
ishuin is offline   Reply With Quote
Old 11-22-2010, 03:01 AM   #2
Warrior Member
War Room Member
 
Join Date: Aug 2010
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Contact Info
Send a message via MSN to theconsultantseo Send a message via Skype™ to theconsultantseo
Default Re: How to insert Adsense Code in the Middle of a Post?

which CMS are you using. Wordpress?
theconsultantseo is offline   Reply With Quote
Old 03-01-2011, 08:04 AM   #3
Warrior Member
 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: How to insert Adsense Code in the Middle of a Post?

So sorry for the delayed response. I didn't know there was a response to my question.

The answer is yes, I'm using Wordpress.

Actually, I've found a script on the web to do it. But, eventually I didn't use it because due to the nature of my site, inserting an ad automatically in the middle of a page will ruin some of my pages.

I'm reproducing the PHP script here for those who may need a similar script. The script is not from me, so I cannot take credit for it, neither can I provide any support.

//Find an appropriate position near the middle of the content to insert an ad
function insert_ad_in_middle_post($content) {
$output = '';
$positions = array();
$endpos = -1;
$trigger = "<p";
if(strpos($content, "<p") === false)
$trigger = "<br";

while(strpos($content, $trigger, $endpos+1) !== false){
$endpos = strpos($content, $trigger, $endpos+1);
$positions[] = $endpos;
}
$middle = sizeof($positions);
while(sizeof($positions) > $middle)
array_pop($positions);
$triggerpoint = $positions[floor(sizeof($positions)/2)];

if ($middle > 2) {
$ad_style = 'clear:both;margin:15px 0 15px 0;padding:0;border:1px solid #ccc;';
if(is_single()) {
$content = substr_replace($content, '<div style="'.$ad_style.'"><!-- Insert Ad Code --></div>'.$trigger, $triggerpoint, 2);
}
}

$content = $output.$content."<div style='clear:both'></div>";
return $content;
}
add_filter('the_content', 'insert_ad_in_middle_post');
ishuin is offline   Reply With Quote
Old 03-01-2011, 09:29 AM   #4
crazzy warrior
 
donkey007's Avatar
 
Join Date: Feb 2011
Posts: 88
Thanks: 6
Thanked 4 Times in 4 Posts
Contact Info
Send a message via Yahoo to donkey007
Default Re: How to insert Adsense Code in the Middle of a Post?

right now i m using two types of ad manager plugin for wordpress.

one is advertising manager which allows me to put ad code in sidebar widget and other plugin ( i dont remember the name now) to insert ad code between top , bottom , before comment box . i dont know it allow to put in the middle of post.

i m using mystique theme which has advertising section in theme settings , which that you just need to insert a tab like [ad] between posts.

donkey007 is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > The Warrior Forum > Adsense / PPC / SEO Discussion Forum

Tags
adsense, code, insert, middle, post

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 11:20 PM.