![]() | | ||||||||
| | #1 |
| Warrior Member Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
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. |
| | |
| | #2 |
| Warrior Member War Room Member Join Date: Aug 2010
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
which CMS are you using. Wordpress?
|
| | |
| | #3 |
| Warrior Member Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
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'); |
| | |
| | #4 |
| crazzy warrior Join Date: Feb 2011
Posts: 88
Thanks: 6
Thanked 4 Times in 4 Posts
|
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. |
| | |
| | |
![]() |
|
| Tags |
| adsense, code, insert, middle, post |
| Thread Tools | |
| |
![]() |