How to Add Google AdSense to Your WordPress Site

How to Add Google AdSense to Your WordPress Site, featured image

There are a lot of ways to monetize your WordPress website, such as affiliate marketing and displaying ads. In fact, showing ads on your site can earn you a sizable amount of money depending on your strategy and traffic figures.

As far as ads platforms go, Google AdSense is one of the best options for most WordPress websites. It’s easy to set up, and since the platform has many advertisers, you’re able to match your site with ads that are relevant to your visitors.

In this tutorial, we’ll talk about how Google AdSense works and how to get ad codes. Then I’ll show you how to add Google AdSense to WordPress both manually and with a plugin. Let’s get to it!

How Google AdSense Works

The Google AdSense home page.

AdSense is an ad network anyone with a website can join. As such, if AdSense approves your website, you can start to display ads from its network on it. Once you’re in, AdSense will pay you either for clicks or impressions on the ads you display. 

Every ad in the network comes from Google Ads publishers. This is a separate platform designed solely for marketers. It enables them to set up campaigns and ads that appear on websites such as yours.

In practice, Google gives marketers a broad range of tools to ensure that only relevant audiences see their ads. This is excellent news for you because it means that the ads you show on your site will be relevant for your visitors.

If you want to join Google AdSense, you need to apply to the platform with an existing website. Ideally, the website should already have some content and an existing audience. Without decent traffic, you’re not going to make much money from ads, regardless of the network you use.

Once your website gets reviewed and accepted (which can take a couple of days), you’re ready to start putting ads on it.

How to Add Google AdSense to Your WordPress Site (2 Ways)

You can publish AdSense ads on your WordPress website either using a plugin or manually.

In both cases, you need to get a snippet of code from AdSense. Let’s look at this step first.

1. Get Your Google AdSense Ads Code

In broad terms, AdSense enables you to put up ads on your website using two approaches:

  1. Manual ads – You can configure ad zones for your site and decide where to place them.
  2. Auto ads – AdSense decides how many ads to display on each page and where to show them (although it does give you some control over ad limits).

In either case, AdSense decides which ads to show on your site. Since the automatic option enables you to decide which pages to show ads on and set a limit, it’s the approach I recommend.

You can enable the auto ads feature for any of your sites by accessing your AdSense account and going into the Ads > Overview screen.

From here, click the Edit button next to your site and enable the Auto ads feature. Now, you’ll see a code snippet similar to the following one:

An example of the AdSense auto-ads code.

Once you have the code, it’s time to place it within WordPress — and there are two ways to do it.

2a. Use a Plugin to Add the Google AdSense Code

Google AdSense’s auto-ads code should go within your website’s header.

The easiest way to add custom code to WordPress is by using a plugin such as Header, Footer and Post Injections:

The Header, Footer and Post Injections plugin

The plugin is remarkably easy to use.

Once it’s installed and activated on your site, click the Settings > Header and Footer option in your WordPress admin. You’ll see the following screen:

Adding code to your website's header

All you need to do is copy the auto ads code you generated with Google AdSense and paste it within one of the fields under <HEAD> PAGE SECTION INJECTION.

Here, you’ll see an option to include the code within all of your pages or just your home page. If you want to maximize ad revenue, I recommend the former option.

Once you paste the code, save the changes — and that’s it! Google ads should start to show up on your website right away.

2b. Add the AdSense Code to Your Theme’s Header Manually

If you want to add custom code to your website’s header manually, the best way to do it is via an FTP (File Transfer Protocol) client such as FileZilla. This lets you connect to your website and edit its files much more easily than from your WordPress dashboard.

For this scenario, you’ll need to edit your theme’s functions.php file and preferably use a child theme. That way, your custom code, such as your Google ads, won’t disappear when you have to update your theme (which happens often).

To get started, access your WordPress root folder and go to wp-content/themes. Look for your theme or child theme’s folder inside and open it. You should be able to spot a file called functions.php inside:

A Cyberduck window showing the functions.php file

Right-click on the file and find the option to open it. This will open the file using your default text editor.

To place your Google AdSense code within your site’s header, you need to add the following code snippet to your functions.php file:

add_action('wp_head', 'adsense_code');
function adsense_code() {
<!-- Your AdSense code goes here. -->

You can change the function’s name from adsense_code() to whatever you prefer.

That’s it! If you ever need to remove Google ads from your site, simply remove the code from your functions.php file or disable the child theme.


If you have a website that gets a lot of traffic, ads are one of the best ways for you to monetize your audience.

With Google AdSense, you get access to what is perhaps the biggest ad network in the world. This means you can display ads that your audience will find relevant, and what’s more, payouts should go off without a hitch to boot.

Learning how to add Google AdSense to WordPress is easy, and you can use either of these two approaches:

  1. Use a plugin to add the Google AdSense code.
  2. Add the AdSense code to your theme’s header through the functions.php file.

Do you have any questions about how to add Google AdSense to WordPress? Let’s talk about them in the comments section below!

Share This Article:
Facebook Twitter

Leave a Reply

Your email address will not be published.

Searching for a free, professional and lightweight WordPress theme? Meet Sydney!
View Theme
Win a Free 1TB CDN Account from KeyCDN Free Entry