Code implementation guide

How to insert ad code in your WordPress site

There are several ways to place AdSense ad code into your WordPress site. Below, you'll find information about some of the ways that you can do this.

Connecting your WordPress site

If you're new to AdSense, one of your first tasks is to connect your site to AdSense. This requires you to copy the code on your AdSense homepage and paste it into the HTML of your page, between the <head> and </head> tags. To do this in WordPress, you can either:
  • Use a plugin to insert the code. You can use one of the plugins that lets you make changes to the 'header' of your site
  • Or, place the code through your WordPress theme settings. We recommend not editing theme files directly. If the theme that you edit is updated, your changes will be overwritten.
Your existing plugin or theme may have a feature for inserting the code. Here are some additional resources from partners that you may be already using:

Be aware that not all themes and plugins allow you to insert code into your site's header. Note that Google isn't responsible for malicious third-party themes or plugins.

Before adding the ad code to your page, make sure that your page complies with the AdSense Programme policies. Note that we may disable ad serving and/or disable your AdSense account at any time if we find your site or ad placement isn't in compliance with our policies.

How to add Auto ads code

Auto ads are a family of ad formats that offer a simple and innovative way for you to monetise your content. To complete the steps to set up Auto ads on a WordPress site, you need to copy and paste the Auto ad code between the <head> and </head> tags of your site. Auto ad code is the same type of code that you added when you connected your site to AdSense. You can use any of the options described in the Connecting your WordPress site section above to add your Auto ad code.

How to insert ad code on your AMP pages

Accelerated Mobile Pages (AMP) is an open source initiative to enable a better web, with sites that are fast, beautiful and monetise well. Learn more about how AMP can help publishers.

Creating an AMP version of your WordPress site

To create an AMP version of your site, we recommend that you use the AMP for WordPress plugin. AMP for WordPress is an open source plugin that Google has contributed to.

After you've installed and activated the plugin, choose your template mode:

  • Native: Choose if you want to have a single AMP version of your site
  • Paired: Choose if you want to have both AMP and non-AMP versions of your site
  • Classic: Choose if your WordPress theme isn't AMP-compatible.

If your WordPress theme is AMP-compatible, you can choose from any of these modes. If you want to test AMP first, you can start with Paired. After testing, you can switch from Paired to Native anytime by visiting your AMP for WordPress plugin settings.

For general AMP support, check out the AMP Project's Getting Support page. If you have specific issues using the AMP for WordPress plugin, you can let the team know via the AMP for WordPress plugin support forum.

Inserting ad code on your AMP pages

After you've created your AMP site, you can show ads on your AMP pages. Depending on the template mode that you selected in the AMP for WordPress plugin, there are different methods that you can use to insert your ad code. If you're unfamiliar with coding, you might want to use an ad plugin or a theme to insert your ad code.

Method of inserting ad code Native Paired Classic
Advanced Ads plugin

(for both Auto ads and ad units)

Mark correct Mark correct Mark correct
Ad Inserter plugin

(for both Auto ads and ad units)

Mark correct Mark correct Mark correct
Insert Headers and Footers plugin

(for Auto ads only)

Mark correct Mark correct Mark correct
Genesis themes

(for Auto ads only)

Mark correct Mark correct Mark incorrect
Note: If you have any issues with these plugins or themes, please contact the respective support forum for help.

How to add ad unit code

Make sure that you've already created the ad units that you need in your AdSense account.


If you're not familiar with coding, but you'd still like to place your ads in specific placements on your site, you might find it useful to use an ads plugin. You can find plugins in the WordPress Plugin Directory

An ads plugin can have extra features that help you to place ads without writing or editing code.

When choosing a plugin, here are some things to bear in mind:

  • Make sure that your theme and plugin are compatible.

  • All plugins offer different features. We recommend that you test a few plugins to find the best fit for you and your site.

  • Google is not responsible for the actions of non-Google plugins.

You might not be able to implement some ad formats such as Page-level ads or Native ads through plugins at this time. If you need assistance with a plugin, contact the plugin developer directly.
WordPress Themes
Themes are a good option if you want an easy way to manage the placement of ad units on your site. We advise you to select WordPress themes that are 'optimised' for AdSense. These themes provide predefined spaces and locations where you can place ad code on pages or post elements of your WordPress site.
Bear in mind that using themes with predefined spaces and locations might restrict you from placing your ad units exactly where you want. Additionally, these themes might not support the layout that best suits your content.
For more information on themes and how to use them, see the official documentation.
Some themes have an 'ads section" built in, but if your theme doesn’t have one, then the easiest way to add your ad units is to use Text Widgets.
You might not be able to implement some ad formats such as Page-level ads or Native ads through themes at this time.
Text Widgets
A Text Widget allows you to add ad units into your WordPress site, in the predefined spaces and locations available from your site's theme.
For more information on Text Widgets and how to use them, see the official documentation.
You might not be able to implement some ad formats such as Page-level ads or Native ads through Text Widgets at this time.


Do you have any questions?

Ask the community

Was this helpful?
How can we improve it?