Why Your AdSense Code Disappears After Every WordPress Update (And How to Fix It)

I stared at my WordPress dashboard, then at my Google AdSense page, then back at my dashboard. Something was wrong.

“Where the hell is my AdSense verification code?”

I had just updated the Astra theme from version 4.13.3 to 4.13.4. A minor update. A point release. The kind you click “Update” on without thinking twice. And just like that — my AdSense code was gone.

What Happened: Theme Updates Replace Everything

Here’s what I didn’t know as a WordPress beginner: when you update a theme, every single theme file gets replaced with the new version. That includes header.php, footer.php, functions.php — all of them.

I had pasted my Google AdSense verification code directly into Astra’s header.php file. It’s the most intuitive thing in the world — Google says “paste this in your head section,” and header.php literally contains the <head> section. So that’s where I put it.

It worked perfectly. Until I updated the theme.

The theme update shipped a brand new header.php — Astra’s clean, original version. My custom AdSense code? Overwritten. Gone. Not in the trash, not recoverable. Just… replaced.

This Is a Classic WordPress Gotcha

If you search “AdSense code disappears WordPress update,” you’ll find thousands of people who hit the same wall. It’s one of those things that seems like a bug but is actually by design. WordPress theme updates are full replacements, not patches.

Any code you manually added to theme files will be wiped out on the next update. And since themes update frequently (security patches, compatibility fixes, new features), this is essentially a ticking time bomb.

The Fix: WPCode (Insert Headers and Footers Plugin)

The solution is embarrassingly simple: don’t put custom code in theme files.

Instead, use the WPCode plugin (formerly known as “Insert Headers and Footers”). This plugin stores your header and footer code snippets in the WordPress database, not in theme files. Theme updates can’t touch it.

I already had this plugin installed on my site. In fact, my Google Analytics tracking code was already living in WPCode’s global header — safe and sound through every theme update. But my AdSense code? I had put it in header.php like an amateur.

The irony.

How to Move Your Code to WPCode (The GUI Way)

  1. Log into your WordPress admin dashboard
  2. Navigate to WPCode (or “Code Snippets”) in the sidebar
  3. Click on “Header & Footer”
  4. Paste your AdSense code in the “Header” box (right alongside any existing code like Google Analytics — they play nice together)
  5. Click Save
  6. Go back to your theme’s header.php and remove the AdSense code you had there (if you had it there)
  7. Test it: Update your theme, then check if the codes are still there. They will be.

How I Actually Did It: WP-CLI One-Liner

I didn’t even open the WordPress admin panel. I used Claude Code to run a single WP-CLI command via SSH:

wp option update wpcode_global_header '[GA tracking code + AdSense verification code]'

Done. Ten seconds. Both my Google Analytics and AdSense codes are now stored in the database, managed by WPCode, and completely immune to theme updates.

Three Approaches Compared

ApproachSurvives Theme Updates?DifficultyBest For
Edit header.php directlyNoEasyNothing. Don’t do this.
WPCode pluginYesEasyAdding scripts to header/footer
Child themeYesMediumExtensive theme customization

A child theme is the most robust solution if you’re doing heavy theme customization — changing templates, modifying CSS, adding custom functions. But for just dropping a script tag into your header? WPCode is the right tool. It’s simple, it works, and you don’t need to maintain a child theme just for a couple of tracking codes.

The Lesson

Never edit WordPress theme files directly for custom code. Use a plugin like WPCode or create a child theme. Your future self — the one who clicks “Update All” without thinking — will thank you.

I lost maybe 10 minutes figuring out what happened and fixing it. But if I hadn’t noticed? My AdSense verification could have been missing for weeks, silently blocking my ad approval. That’s the real danger — these failures are silent.


How This Post Was Made

This post documents a real problem I hit on this very blog. I updated the Astra theme and lost my AdSense code. The fix took 10 seconds with WP-CLI. The blog post was written and published using Claude Code — I described what happened, and it turned the experience into a structured, searchable article. The entire workflow (writing, formatting, SEO optimization, scheduling) was handled through a single Claude Code session via terminal.


This post was written with AI assistance using Claude Code. The experience described is real, the problem was real, and the fix works. AI helped structure the narrative and optimize it for search. Learn more about how this blog uses AI.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top