If you are experimenting with AdSense ads on your blog to achieve the best placement, you may also looking to display AdSense in your blog posts. No, I’m not talking about wrapping ads around the post body. Lets say, you want to display an AdSense ad unit after every two paragraphs in your post body which you may have seen on many websites also. If you are looking to do so with your WordPress blog, it is possible with plugins as well as without using plugins.

AdSense inside WordPress blog posts
Hubpages.com displays AdSense ads between the post content.

Code to show AdSense ads in WordPress posts

Note: Below given method involves manual editing of your WordPress theme files. Make sure to back up your theme before proceeding.

  1. First, open your theme directory and edit single.php file.
  2. Search for <?php the_content(); ?> (Ctrl + F and search the string) and replace it with the below given code:
    <?php
    $block = 3; // this indicate that ad will appear after the 3rd paragraph
    $content = apply_filters('the_content', get_the_content());
    $content = explode("</p>", $content);
    for($i = 0; $i < count($content); $i++ ) {
    if ($i == $block) { ?>
    <div style="margin: 10px 0;">PUT YOUR ADSENSE CODE HERE</div>
    <?php }
    echo $content[$i] . "</p>";
    } ?>

    Change $block value according to your requirement. Replace “PUT YOUR ADSENSE CODE HERE” with your AdSense ad unit code.

  3. Save changes. Done! You may also tweak it to adjust according to your blog layout with CSS positioning.

WordPress Plugins to put AdSense ads in WordPress posts

If you are not good at coding, you may use Ad Injection or Insert AdSense WordPress plugins for the same. The plugins are very easy to use and provide a variety of options to control ads on your WordPress blog. You will be able to add ads in posts by the means of shortcodes with these plugins.

If you are meeting difficulties with the manual method, feel free to ask for help.

Also read: Show AdSense Ads between WordPress posts