Have you ever wondered how is it possible to integrate AdSense or any other ads into or between your Wordpress posts ? Of course you have. This method does not require any third-party plugins whatsoever. For example, we all know that on a single page only three AdSense ads will appear. I’ve seen people that added the ad code between their posts on the index page. Guess what ? The first ads showed up alright but the other ones not and this resulted in the loss of precious space as the spots where the ads should have been were left blank. You can implement this method very fast as it’s very simple and you don’t need to be an advanced coder to get it done !
If you want to integrate ads into your posts here’s what you need to do. First of all let’s begin with defining the CSS class we’ll be using.
The following code is for right-orientated ads (like the ones i use on my blog).
1
2
3
4
5
| .ad-right {
display:block;
float:right;
margin: 0px 0px 5px 10px;
} |
The next code is for left-orientated ads.
1
2
3
4
5
| .ad-left {
display:block;
float:left;
margin: 5px 10px 0px 0px;
} |
As you can see, the differences between the two classes are not so big. Feel free to play with them until you get the desired effect or if you don’t have any CSS knowledge at all you can use them as given. After you decide which class you will use, copy the code into your style.css. Thats it for the CSS part.
Let’s move along and edit our theme files. Whether you want to show your ads on the index page or the page containing just the article you will need to look for the following code:
By default any wordpress theme will have that code in it’s template file and it doesn’t matter what’s after it because many themes use custom and different code. After you located the code be sure to add the following lines exactly before it:
1
2
3
| <div class="ad-right">
////Replace me with your ad code////
</div> |
Replace the line that says so with your ad code. Notice the class that is used. You might want to change that with ad-left as i told you before.
Ok, so now you have in-content ads.
Now lets move forward and add some ads between your posts on the index page.
In your index page template find the following code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Again bare in mind that you may not find the exact code. If you don’t have that exact code just make sure you find the have_posts() function. Add the following code exactly before it:
1
2
3
4
5
6
| <?php
$post = 1;
$ad1 = 1;
$ad2 = 3;
$ad3 = 5;
?> |
The above code uses the $ad1, $ad2, $ad3 variables to define after which posts the ads will be shown. The variable $post stores the post number and will be incremented later.
Now before the closing of the div that marks the ending of the post content (something like this < / div > < ! -- End of Post -- >) add the following lines:
1
2
3
4
5
6
| <?php if ($post == $ad1 || $post == $ad2 || $post == $ad3) { ?>
<p><center>
////Replace me with your ad code////
</center></p>
<?php }
$post++; ?> |
As you can see at the end of the code we incremented the post variable.
If you want to know how to display ads from multiple advertising companies using the same code just drop me a comment and i will explain how to achieve that.
I’ve tested this method with ads from AdSense, BidVertiser, WidgetBucks, BlgAds, Chitika and AdBrite. The reason i’m not writing a tutorial for each of them is because all you need to do is to paste your ad code in the upper mentioned spot.
Tips on how to integrate ads between and into your Wordpress posts
Have you ever wondered how is it possible to integrate AdSense or any other ads into or between your Wordpress posts ? Of course you have. This method does not require any third-party plugins whatsoever. For example, we all know that on a single page only three AdSense ads will appear. I’ve seen people that added the ad code between their posts on the index page. Guess what ? The first ads showed up alright but the other ones not and this resulted in the loss of precious space as the spots where the ads should have been were left blank. You can implement this method very fast as it’s very simple and you don’t need to be an advanced coder to get it done !
If you want to integrate ads into your posts here’s what you need to do. First of all let’s begin with defining the CSS class we’ll be using.
The following code is for right-orientated ads (like the ones i use on my blog).
The next code is for left-orientated ads.
As you can see, the differences between the two classes are not so big. Feel free to play with them until you get the desired effect or if you don’t have any CSS knowledge at all you can use them as given. After you decide which class you will use, copy the code into your style.css. Thats it for the CSS part.
Let’s move along and edit our theme files. Whether you want to show your ads on the index page or the page containing just the article you will need to look for the following code:
By default any wordpress theme will have that code in it’s template file and it doesn’t matter what’s after it because many themes use custom and different code. After you located the code be sure to add the following lines exactly before it:
Replace the line that says so with your ad code. Notice the class that is used. You might want to change that with ad-left as i told you before.
Ok, so now you have in-content ads.
Now lets move forward and add some ads between your posts on the index page.
In your index page template find the following code:
Again bare in mind that you may not find the exact code. If you don’t have that exact code just make sure you find the have_posts() function. Add the following code exactly before it:
The above code uses the $ad1, $ad2, $ad3 variables to define after which posts the ads will be shown. The variable $post stores the post number and will be incremented later.
Now before the closing of the div that marks the ending of the post content (something like this < / div > < ! -- End of Post -- >) add the following lines:
As you can see at the end of the code we incremented the post variable.
If you want to know how to display ads from multiple advertising companies using the same code just drop me a comment and i will explain how to achieve that.
I’ve tested this method with ads from AdSense, BidVertiser, WidgetBucks, BlgAds, Chitika and AdBrite. The reason i’m not writing a tutorial for each of them is because all you need to do is to paste your ad code in the upper mentioned spot.