Most of the times my readers and blogger friends ask about how to control the adsense ads placement inside the content of a post. Well, today let me describe it to you my way. What I use is a simple shortcode I wrote.


How to put Adsense Ads within the Content

First of all go to your functions.php (Appearance>>Edit>>Theme Functions(functions.php)) and put the code (the code below) at the end of it. After that click Update. (Do save a copy of your functions.php file before modifying it.)

 function the_adsense($atts) { return ' <div class="post-link-ad"> Put Your Adsense Code Here </div>'; } add_shortcode('ads1', 'the_adsense'); 

After adding this code all you have to do is to put [ads1] inside your post’s content (Visual or HTML works in both). The ad will show up where ever you placed the ad shortcode. Just like I added an ad below


Can I style it?

Yes go to style.css file  (Appearance>>Edit>>Style.css)At the end put this class. This step is optional.

 .post-link-ad{ text-align:center; /*It will make your ad displayed in center*/ background-color: white; /*Or anything you want*/ padding:5px; margin:5px; } 

Can I use two or more ads like this?

Yes of-course you can. All you have to is change the name of function and its shortcode e.g. another ad shortcode is below

 function new_adsense($atts) { return ' <div class="post-link-ad"> Put Your Adsense Code Here </div>'; } add_shortcode('ads2', 'new_adsense'); 

To put this inside the content you should add the shortcode [ads2] in Visual or HTML editor.


Your Turn:

  1. Tell me if you are still confused at any step.
  2. Did you find it useful? Are you planning to use it in a different way? Tell us!