How to Display/Insert Adsense Ads inside WordPress Posts?

If you’re an Adsense publisher, you might’ve known the importance of CPC (cost per click) and CTR (click through rate). One should improve the performance of CPC and CTR if he wants to earn high from Google Adsense. Generally, webmasters try to place the advertisements at the beginning of the article (under the title) to get more clicks. But, this tactic won’t work in all the cases. Placing ads inside the article also has the highest click rate and so if you could insert your Adsense ads within your WordPress post, then CTR will eventually increase as there will be more chances for getting content-related ads.

Also see: Try to make use of the Responsive Adsense ads for better earnings.

Manually Display Adsense Ads Anywhere inside your WordPress Posts

This is very simple. By creating a shortcode in the functions.php file, you can achieve this.

  1. Login to your WordPress dashboard > go to Appearance > Editor.
  2. Click on the “functions.php” file from the right side panel.
  3. Copy and paste the following code in your functions.php file at the end.

    function adsense1() {
    return ‘
    <!– Start Here –>
    Paste Your Adsense Code Here
    <!– End Here –>
    add_shortcode(‘adsense’, ‘adsense1’);

  4. Replace the lines in red color with your Google Adsense ad script that you wish to appear inside your WordPress post and click save.
  5. Starting now, whenever you compose a new post, simply go to “HTML mode” in the editor and type [adsense] at the point where you wish to display this Adsense ad and click “Publish”.Adsense Ads inside WordPress Posts
  6. You can even add styles to your displayed advertisement.
    • Go to Appearance > Editor and open style.css file.
    • Add the following code at the end and click save.

      .adstyle {
      border:solid 1px #c7c7c7;

    • This is a sample code and you can modify it as per your blog colors.

Note: If you’re adding style to your ads, then don’t forget to use <div class=”adstyle”>[adsense]</div> instead of [adsense] in the step 5.

This is a handy shortcode method to insert advertisements or banners within your post content. Not just Adsense ads, you can follow this guide to add any code inside your posts.

Note: Although, there are plugins to add Adsense ads inside WordPress posts, I personally prefer adding them manually as plugins will increase the load time of our blog.


Leave a Reply

Your email address will not be published. Required fields are marked *