Place AdSense inside single post using WordPress

All you guys using WordPress and wondering how to place Google AdSense inside single post here is simple solution.

This is what you want – AdSense inside single post, in my case aligned left with text aligned around AdSense unit box.

On my example I use ThemeJunkie Freshlife theme, but I think that this code will work on other WordPress themes as well.

You don’t need any plugin or widget, just a simple code inside your original single.php file. That file is responsible for displaying single post, and if you want to change its appearance you need to edit that file and do changes inside.

This code you can use to add AdSense unit box, or some other banner or custom message for your visitors. I will give you example of adding Google AdSense code inside single post on sites running with WordPress.

Hope you will find this code interesting and use it. Keep in mind to do backup first or to copy original single.php file first. In case something goes wrong, you can easily restore files like they were before any changes.

OK – if you wanna Google AdSense to show inside single post, keeping on mind bigger CTR this is the way to do it.

Edit your original single.php file and find this part of code

<?php the_content(); ?>

When you have find code above make sure to replace it with this one

$paragraphAfter= 1;
$content = apply_filters(‘the_content’, get_the_content());
$content = explode(“</p>”, $content);
for ($i = 0; $i <count($content); $i++) {
if ($i == $paragraphAfter) { ?> <div style=”display:block;float:left;margin: 5px 5px 5px 5px;border-right: 2px solid #d4d4d4;”>
<script async src=”//”></script>
<!– your adsense code –>
<ins class=”adsbygoogle”
(adsbygoogle = window.adsbygoogle || []).push({});
echo $content[$i] . “</p>”;
} ?>

Make sure to place your original AdSense code instead I provided in this example. Also, you can make your own style – I have this one and it works for me. You can align your AdSense box to go center or right aligned, it is up to you.

Before you do any of these steps, once again I wanna give you advice to save original single.php file first.

Good luck with positioning AdSense inside single post.

Add Comment