WordPress Google Adsense: Speeding Up Ad Placement

Load the AdSense script once on WordPress, with Site Kit, a header plugin or functions.php, and stop ads hurting page speed and Core Web Vitals.

WordPress Google Adsense: Speeding Up Ad Placement

Google AdSense is still the default way to earn from a WordPress site, but it is easy to add it in a way that slows pages down. The usual culprit is pasting the full ad code into every widget and post, which loads Google’s AdSense script once for every ad on the page. This guide shows how to load the script once, the cleanest ways to do that on a modern WordPress site (classic or block theme), and a few other changes that keep ads from hurting your Core Web Vitals.

Why duplicate AdSense code slows your site

Every AdSense ad unit you copy from your account comes in two parts:

  • The loader script, which is the same for every ad unit on your account. It currently looks like this:
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXXX" crossorigin="anonymous"></script>
  • The ad slot, the <ins class="adsbygoogle"> block plus the short (adsbygoogle = window.adsbygoogle || []).push({}); line, which is different for each unit.

The browser is good at caching, so a repeated loader is not downloaded five times, but each copy is still parsed and adds noise to the page. Loading it once in the page head is what Google recommends and gives the browser a clear, early hint to start fetching it.

Step 1: add the loader script once

Pick whichever of these suits your site. Do not use more than one, or you are back to loading it twice.

Option A: Site Kit by Google

Google’s own Site Kit plugin connects your site to AdSense and places the loader script for you. It also handles Auto ads if you want Google to choose ad positions. This is the simplest route if you do not want to touch code, though Site Kit is a fairly heavy plugin if you only use it for this.

Option B: a header code plugin

Plugins such as WPCode let you paste the loader script into a “header” box that is output on every page. This works with any theme and survives theme updates.

Option C: your child theme’s functions.php

If you already maintain a child theme, add this, replacing the publisher ID with your own:

add_action( 'wp_head', function () {
    echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXXX" crossorigin="anonymous"></script>';
}, 5 );

Avoid editing header.php in your parent theme directly. The change is lost at the next theme update, and block themes such as Twenty Twenty-Five do not have a header.php at all. Whatever you edit, back up first: a typo in functions.php can take the site offline.

Step 2: strip the loader from each ad placement

Go through every widget, Custom HTML block and post where you have pasted ad code and delete the loader <script async src=...adsbygoogle.js...> line. Leave the <ins> block and the push line in place, because those are what actually display each ad. If you use reusable blocks (now called synced patterns) for your ad units, you only need to edit each pattern once. Our guide to WordPress block editor basics in 2026 covers patterns if you have not used them yet.

Step 3: clear your caches and check

Purge your caching plugin and any CDN cache, such as Cloudflare, then view the page source of a post with several ads. Search for adsbygoogle.js: you should find it once. Open the browser developer tools, go to the Console tab and check for AdSense errors such as “All ins elements already have ads”, which usually means a leftover duplicate push line.

Other ways to stop ads hurting page speed

  • Reserve space for each ad. Ads that pop in and push content down cause layout shift, which counts against your Core Web Vitals. Wrap manual ad units in a container with a sensible min-height for their position.
  • Do not stack too many units. Each one adds requests and third-party scripts. Three well-placed units usually earn about as much as six crammed ones and keep readers on the page.
  • Keep ads.txt valid. AdSense warns you if ads.txt is missing or wrong, and earnings can suffer. Site Kit and most SEO plugins can manage it for you.
  • Tidy the rest of the page. Ads are rarely the only slow part. Small wins such as removing query strings from static assets and blocking spam bots with Cloudflare’s free rules all add up.

Manual ads or Auto ads?

Auto ads let Google decide where ads go and how many to show. They need only the loader script, so they are the lightest to set up, and you can limit density and exclude pages from the AdSense dashboard. Manual units give you more control over layout and speed. Many sites use both: a few manual units in fixed positions, with Auto ads switched on for anchor or vignette formats only. If AdSense is not paying enough to justify the speed cost, we have looked at Google AdSense alternatives as well.

FAQ

Does the loader have to go in the head?

Google recommends the head, but because the script is async it does not block the page from rendering wherever it sits. What matters most is that it appears once.

Can I lazy load AdSense ads?

AdSense already delays some ad requests itself. Third-party lazy loading tricks that change how AdSense code runs can breach the programme policies, so stick to the official code and Google’s own settings.

Will removing the duplicate scripts affect earnings?

No. Every ad slot still loads normally. You are only removing redundant copies of the same loader.

If you have any questions or feedback on this guide, please leave us a comment below.

🛠️

Gear We Recommend

A few general tech accessories worth having alongside this.

Browse our General Tech Accessories picks on Amazon

As an Amazon Associate, TechyGeeksHome earns from qualifying purchases.


Discover more from TechyGeeksHome

Subscribe to get the latest posts sent to your email.

Andrew Armstrong

Andrew Armstrong is a UK-based IT professional with 26+ years of hands-on experience in Windows, Windows Server, SCCM/ConfigMgr, Intune, Active Directory, PowerShell and enterprise infrastructure.

He founded TechyGeeksHome in 2010 and has published 770+ practical guides to real-world IT problems. He also builds free Windows utilities, including Ultimate Settings Panel, which has been downloaded over 850,000 times.

Part of The Geek Network