Place Ads in the Middle of Your Posts

Do you want ads that can be easily picked by the users – so that your advertisers get more attention. It is simply possible with a small hack on wordpress.

With this WordPress Hack you can easily place your ads in between your posts and that also automatically. You don’t need to edit the codes every time nor you need to place any tags or install any plugins.

WordPress Hack for Ads
Follow the procedure below and it will enable ads in the middle of your blog post.

I assume that you know a bit of coding – just follow if you need to ask some thing you can always post comments. Login to your wordpress admin and look for “appearance” tab on the left-column – just click on the “editor” link and then you will land on to the template-editing page.

Step 1
Just search for the file name “single.php” the file list will be on the right-column.

Step 2
Search for: <?php the_content(); ?>

Step 3
Replace it with the following code

—————-

<?php
  $content = apply_filters('the_content', $post->post_content);  //get the post content store in $content
  $save = explode("</p>", $content);  //Separate the content into <p> blocks
  $tcount=0; //this is count for number of <p> blocks
  $adon=0;  //this is a variable so you don't show ads more than once.
  foreach($save as $item) {
    echo $item;  //print the <p> block
    echo "</p>";
    if(preg_match('/<p> /',$item)==0 && $tcount>=1 && $adon==0) {
                                $adon=1;
?>
YOUR ADV CODE
<?php
    }
 if(preg_match('/<p> /',$item)==0 && $tcount>=4 && $adon==1) {
                                $adon=2;
?>
ANOTHER ADV CODE IF YOUR POST HAVE MORE THEN 4 PARAGRAPHS
<?php
   }
   $tcount++;
 }
?>


—————-

You are done!

wordpress hack

Conclude
This wordpress hack will easily let you place the desired ads – or you can also use it to place any thing you like – such as related posts codes – or any other code you wish to place.

Happy Blogging!

 

Do you want ads that can be easily picked by the users – so that your advertisers get more attention. It is simply possible with a small hack on wordpress.

 

With this WordPress Hack you can easily place your ads in between your posts and that also automatically. You don’t need to edit the codes every time nor you need to place any tags or install any plugins.

 

WordPress Hack for Ads

Follow the procedure below and it will enable ads in the middle of your blog post.

 

I assume that you know a bit of coding – just follow if you need to ask some thing you can always post comments. Login to your wordpress admin and look for “appearance” tab on the left-column – just click on the “editor” link and then you will land on to the template-editing page.

 

Step 1

Just search for the file name “single.php” the file list will be on the right-column.

 

Step 2

Search for: <?php the_content(); ?>

 

Step 3

Replace it with the following code

 

—————-

<?php

$content = apply_filters(‘the_content’, $post->post_content); //get the post content store in $content

$save = explode(“</p>”, $content); //Separate the content into <p> blocks

$tcount=0; //this is count for number of <p> blocks

$adon=0; //this is a variable so you don’t show ads more than once.

foreach($save as $item) {

echo $item; //print the <p> block

echo “</p>”;

if(preg_match(‘/<p> /’,$item)==0 && $tcount>=1 && $adon==0) {

$adon=1;

?>

YOUR ADV CODE HERE

<?php

}

if(preg_match(‘/<p> /’,$item)==0 && $tcount>=4 && $adon==1) {

$adon=2;

?>

ANOTHER ADV CODE IF YOUR POST HAVE MORE THEN 4 PARAGRAPHS

<?php

}

$tcount++;

}

?>

—————-

 

You are done!

 

Conclude

This wordpress hack will easily let you place the desired ads – or you can also use it to place any thing you like – such as related posts codes – or any other code you wish to place.

 

Happy Blogging!