How to Insert Google Ad into WordPress
Placing Google ads on your WordPress site is a straightforward way to monetize your content or track conversions from your campaigns. Whether you're running display ads with AdSense or tracking ad performance with Google Ads, you can get everything set up in minutes. This tutorial will walk you through the process step-by-step, using both easy-to-use plugins and manual methods for more control.
Before You Start: Getting Your Google Ad Code
First things first, you need the actual code snippet to add to your site. The code you need depends on your goal. Are you trying to display ads on your site to earn money (AdSense), or are you trying to track a customer's action after they clicked one of your ads (Google Ads)?
For Displaying Ads (Google AdSense)
Google AdSense is the program that lets you rent out space on your website for advertisers. When a visitor sees or clicks an ad, you earn a small commission. Before you can get your code, you need to sign up for an AdSense account and get your site approved, which can sometimes take a few days to a few weeks.
Once your site is approved, you have two main types of ad code you can use:
- Auto Ads Code: This is a single piece of code that you add to every page of your site. Google's AI then automatically finds the best places to show ads on your site for you, balancing user experience and revenue. This is the simplest option and the one AdSense recommends starting with.
- Ad Unit Code: If you want precise control over where ads appear, you can create specific "Ad Units" inside AdSense. You can define the size, shape, and type of ad (e.g., a banner, a square), and AdSense will give you a specific code snippet just for that ad unit. You then place that code exactly where you want the ad to show up.
To get your code, log into your Google AdSense account. You'll find the general Auto Ads code under the Ads > By site section. You simply copy this code to your clipboard.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
For Tracking Conversions (Google Ads)
If you're running campaigns on Google Ads and sending traffic to your WordPress site, you need a conversion tracking tag. This code snippet helps you measure valuable actions, like when a user fills out a contact form, signs up for your newsletter, or makes a purchase.
The Google Ads tag consists of two parts:
- Global Site Tag (gtag.js): This main tag needs to go on every page of your website, usually in the
<head>section. It sets up the basic foundation for tracking. - Event Snippet: This is a smaller piece of code that goes only on the page where the conversion happens, like your "Thank You for Your Purchase" or "Form Submitted" page.
You can create and find these snippets inside your Google Ads account under Tools and Settings > Measurement > Conversions. Create a new conversion action, and Google will provide you with the necessary tags.
Method 1: The Easiest Way Using a Free Plugin
For most WordPress users, a plugin is the safest and quickest way to insert Google ad code. You won't have to touch your theme's underlying code, which removes the risk of accidentally breaking your site. Our favorite plugin for this is the free WPCode - Insert Headers and Footers.
It's versatile enough to handle both AdSense Auto Ads and Google Ads conversion tags with ease.
Step-by-Step Guide with WPCode:
Step 1: Install and Activate WPCode
From your WordPress dashboard, navigate to Plugins > Add New. In the search bar, type "WPCode." Find the plugin by WPCode and click Install Now, followed by Activate.
Step 2: Add Your AdSense Auto Ads or Global Site Tag
Once activated, you'll see a new "Code Snippets" menu item in your dashboard sidebar. To add sitewide code (like AdSense Auto Ads or the Google Ads Global Site Tag), follow these steps:
- Hover over Code Snippets and click on Header &, Footer.
- You'll see three boxes: Header, Body, and Footer.
- Paste your code into the Header box. Both AdSense's Auto Ads script and Google Ads' Global Site Tag are meant to go here in the
<head>section of your site's HTML. - Click Save Changes at the top right.
That's it! The code is now present on every single page of your website, just as Google requires. AdSense will begin scanning your site to place ads, and the Google Ads tag will begin monitoring traffic.
What about AdSense Ad Units or Google Ads Event Snippets?
Plugins like WPCode also let you add snippets that only run on specific pages. This is perfect for Google Ads event snippets that should only fire on a thank you page.
Instead of using the "Header & Footer" section, you'd go to Code Snippets > Add Snippet. Here, you can add a new "Custom Code" snippet, paste your event snippet code, and then use the "Smart Conditional Logic" to set rules, such as "Show only if the Page URL is..." and then enter the URL of your thank you page. This gives you powerful control without writing any PHP.
Method 2: Placing Ad Code Manually (For More Control)
If you're comfortable editing WordPress a bit more directly and want precise placement of AdSense ad units, you can skip the plugin and add the code manually. There are two primary ways to do this.
Using Widgets for Sidebars and Footers
The simplest manual method involves using WordPress's built-in widget system. This is ideal for adding banner or box ads to your site's sidebar, footer, or any other widget-ready areas your theme provides.
- From your WordPress dashboard, go to Appearance > Widgets.
- Find the widget area where you want to place the ad (e.g., "Sidebar," "Footer Column 1").
- Click the
'+'icon to add a new block and search for "Custom HTML." - Click on the Custom HTML block to add it to your widget area.
- In the text field that appears, paste your AdSense Ad Unit code. Make sure you use the code for a specific ad unit, not the general Auto Ads code.
- Click Update to save your changes.
The ad will now appear in that position on your live site (though it can sometimes take a few minutes for AdSense to serve a live ad into the new block).
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Editing Theme Files (Advanced Users Only!)
For ultimate control, you can insert ad code directly into your theme's PHP files. This lets you place ads in specific spots plugins and widgets can't reach, like in the middle of a blog post's content or directly below the post title.
A strong word of caution: Before you attempt this, you should always use a WordPress child theme. If you edit your main theme's files directly, your changes will be completely erased the next time the theme updates.
Here’s a general example of how to add an ad inside the content of your blog posts:
- Ensure you have a child theme active. From the dashboard, go to Appearance > Theme File Editor.
- From the file list on the right, find the template you want to edit. For single blog posts, this is often a file named
single.phpor a content template file likecontent-single.php. - Locate the part of the code where you want to insert the ad. For example, to place an ad after the opening content, look for a function like
the_content(). You can paste your ad code just above or below it.
<?php
if ( is_singular( 'post' ) ) {
the_content(),
// --- Google AdSense Ad Unit Code ---
// PASTE YOUR AD CODE SNIPPET HERE
// ---------------------------------
} else {
the_excerpt(),
}
?>- Click Update File to save your changes.
This method offers incredible flexibility but requires a basic understanding of WordPress theme structure. For 99% of people, a good plugin is the better choice.
Final Thoughts
Inserting Google Ads into WordPress is totally manageable once you know your options. Using a plugin like WPCode is the quickest and safest method for adding sitewide header tags for AdSense Auto Ads or Google Ads tracking. For more granular control over individual ad placements, the widget area or manual theme edits offer greater flexibility.
Once your ads are up and running, your job shifts from setup to analysis. Tracking ad revenue, conversion rates, and campaign performance across different platforms becomes the next challenge. We built Graphed to solve exactly that problem. By connecting your Google Ads, Google Analytics, and other data sources, you can use simple natural language - not complex BI tools - to build real-time dashboards that show you what's actually working, allowing you to focus on growing your business instead of wrestling with spreadsheets.
Related Articles
Facebook Ads for Clinics: The Complete 2026 Strategy Guide
Learn how to use Facebook Ads for Clinics to grow your patient base in 2026. Complete guide covers targeting, campaign types, and compliance requirements.
Facebook Ads for Salons: The Complete 2026 Strategy Guide
Learn how to run profitable Facebook ads for hair salons and beauty spas in 2026. This comprehensive guide covers targeting, ad creation, budgeting, and proven strategies to attract more clients.
Facebook Ads For Beauty Salons: The Complete 2026 Strategy Guide
Learn the proven Facebook ad strategies that successful beauty salons are using to attract new clients, increase repeat bookings, and grow their revenue in 2026.