Hey there everyone. Does anyone know a plugin for Wordpress that enables me to automatically insert an AdSense ad in the middle og my articles? I have found a few, but they all seem to have problems. As I said, the plugin needs to be able to insert the ad in the middle or after a set amount of sentences. Thanks! Note: I know I misspelled the title... argh..
You have to do a bit of coding... Open your “single.php†file (in your template folder) Search: <?php the_content(); ?> PHP: Replace with: 01 <?php 02 $content = apply_filters('the_content', $post->post_content); //get the post content store in $content 03 $save = explode("</p>", $content); //Separate the content into <p> blocks 04 $tcount=0; //this is count for number of <p> blocks 05 $adon=0; //this is a variable so you don't show ads more than once. 06 foreach($save as $item) { 07 echo $item; //print the <p> block 08 echo "</p>"; 09 if(preg_match('/<p> /',$item)==0 && $tcount>=1 && $adon==0) { 10 $adon=1; 11 ?> 12 ADSENSE HERE 13 <?php 14 } 15 if(preg_match('/<p> /',$item)==0 && $tcount>=4 && $adon==1) { 16 $adon=2; 17 ?> 18 ANOTHER ADSENSE IF YOUR POST HAVE MORE THEN 4 PARAGRAPHS 19 <?php 20 } 21 $tcount++; 22 } 23 ?> PHP: Hope it helps...
Nothing at all.. all will work the normal way as previous - its just that you split your content in parts to place advertisement codes... that it hope it helps...