How to Manually Place AdSense Ad Units in WordPress

Last updated:

Contrary to what so many bloggers think, Google AdSense can still very much be a lucrative way of monetizing a website.

While ad management companies, such as AdThrive and Mediavine, are surging in popularity, doing it yourself with AdSense can often lead to great results.

In this article I am going to explain how you can manually add AdSense ad units in your content in a proper and clean way, so you can maximize your advertising earnings.

Why Place Ads Manually?

With AdSense, there are two ways to have ads placed on your site.

You can either choose to have Google automatically place ads throughout your site, where they seem fit, or you can place ads manually, where YOU want them to be.

I have always done this the manual way, because that has always given me the best returns. When you spend a bit of time working out which ad units and which locations work best, managing ads the manual way can be quite a lucrative affair.

So if you’re planning on joining an ad management company but you haven’t met their thresholds yet, or if you simply want to keep managing ads yourself, please read on.

Manually placing AdSense ad units throughout your content is super easy.

How to Manually Place AdSense Ad Units

In short, I’m going to create a WordPress shortcode that allows you to easily add an AdSense ad unit to your content in a clean and manageable way.

In the example below I am using a 300 x 250 px display ad unit, because I find that ad unit offers the best returns.

1: Create an AdSense Ad Unit

The first step is to create an AdSense ad unit from within your Google AdSense dashboard.

In the Ads section, choose to create a new display ad:

Create new AdSense display ad

In the next screen you can configure this new ad unit, which is really easy:

AdSense display ad settings

Select a fixed ad size with a width of 300 pixels and a height of 250 pixels. Also give this ad unit a good name, for example “display-fixed”.

Once you’ve done all that, you will get the ad unit code:

AdSense display ad code

Copy and paste this ad unit code into a temporary text file.

2: Create a WordPress Shortcode

This is the exciting part, because we’re now going to create a WordPress shortcode with some PHP code.

We can write this code directly into the functions.php file, but my preferred way of doing this is with a plugin called Code Snippets. This plugin allows you to add simple pieces of code to your WordPress blog without touching the functions.php file.

The benefit of using Code Snippets is that the functions.php file (which is a super important theme file) remains untouched, and you can manage all custom code changes in one place.

In your WordPress dashboard, navigate to the plugins section, and install and activate the Code Snippets plugin:

Code Snippets WordPress plugin

Navigate to the plugin and choose Add New snippet. In the editor box, add PHP code as per below image, and give this snippet an appropriate name:

PHP code to create a WordPress shortcode

This is the copy/paste version of the code, where you will need to replace the words “ad unit code” by the actual ad unit code you picked up in the previous step:

function contentad_shortcode() { 
 
$string .= 
'ad unit code';
 
return $string; 
 
}

add_shortcode('content_ad', 'contentad_shortcode');

Once you’ve created the code snippet and everything looks good, with no syntax errors, click Save Changes and Activate.

Congratulations, you’ve just created a WordPress shortcode.

3: Place Ad Unit in Content

The last step is the easiest, and most rewarding step. All you need to do now is add a WordPress shortcode in your content to display the AdSense ad unit.

Open a blog post in editor mode, and add the following shortcode wherever you want an ad unit to appear:

[content_ad]

You can do this in the Classic editor as well as in the Block editor.

When you test this, you may not immediately see an ad appear, because it can take some time for Google AdSense to sort this out for you.

Final Thoughts

That’s how easy it is to manually place AdSense ad units in your WordPress blog.

I recommend you place a display ad unit every 3 or 4 paragraphs, with each paragraph on average not longer than 2 sentences. This may sound like a lot of ads, but it’s actually pretty standard.

Also note that you can create different shortcodes for different ad units. I personally prefer to use the 300px by 250px display ad unit, but you’re free to experiment with whatever ad unit you like, and see what works best for your site.

Join Blog Pioneer

​JOIN BLOG PIONEER

​​Subscribe now and learn how to grow your ​blog into a thriving business with effective SEO and monetization strategies.

​​BONUS: ​​3 actionable SEO tips you can implement today to give your blog posts an immediate boost!

 
AJ Mens

I have been running an online business since 2015 and am using Blog Pioneer to help you achieve financial success online.

Leave a Comment