Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Theme update overwrites tracking code: how to fix it

OPS-235High impactDetectedBy FunnelGuardPublished Updated
On this page

What this issue is

A WordPress theme is a folder of files. When the theme author releases a new version, WordPress deletes the old folder and puts the new one in its place. Any edit you made inside that folder is gone.

This often hits tracking code (a GA4, Meta Pixel or Google Ads snippet pasted into header.php), custom PHP added to functions.php, CSS edits in style.css, and edited template files such as checkout or form templates. The site still looks fine, so nobody notices that tracking or a form tweak has vanished.

Why it costs you leads or sales

If the tracking snippet disappears, ad platforms stop receiving conversions. Smart bidding in Google Ads and Meta then optimises on less data, and reports show a sudden drop that looks like a demand problem. If a custom form hook or checkout edit is lost, the form or checkout may behave differently or fail.

How a theme update loses conversions
  1. Theme updateOld theme folder replaced
  2. Custom code deletedTracking snippet gone from header.php
  3. Conversion eventNo hit sent to GA4 or ad platforms
  4. Ad optimisationBidding learns from missing data

The update itself succeeds, so the loss goes unnoticed.

Reported conversions around a theme updateExample numbers
Reported conversions around a theme update (example)Week before: 40 conversions per week; Update week: 18 conversions per week; Week after: 0 conversions per week0153140180Week beforeUpdate weekWeek afterconversions per week

Example: illustrative numbers showing reported conversions falling to zero the week the snippet is deleted while real leads continue.

How to check if your site has it

Check whether an update removed your code
  1. Check when the theme last updatedWordPress

    In WordPress go to Appearance > Themes and note the version. Compare it with the date your conversions dropped.

  2. View the page source

    Open your site, press Ctrl+U (Cmd+Option+U on Mac) and search for your measurement ID, such as G-XXXXXXX, or for fbq( and gtag(.

  3. Check the live tag in the browser

    Open DevTools, go to the Network tab, reload, and filter for collect, gtm or facebook. No requests means the tag is not loading.

  4. Compare the theme with a clean copy

    Download the same theme version from its source and compare it with your files, or check your backups from before the update.

  5. Test a conversion

    Submit a test form or start a test checkout and watch Tag Assistant or GA4 DebugView for the event.

How to fix it

First restore the lost code from a backup or from your records. Then put it somewhere an update cannot overwrite. The best place depends on what the code does.

Where to keep each kind of customisation
CustomisationSafe home
Tracking snippets (GA4, Meta, Ads)Google Tag Manager, or a header/footer plugin
PHP functions and hooksA child theme functions.php or a small custom plugin
CSS tweaksAppearance > Customize > Additional CSS, or child theme
Edited template filesSame file path inside a child theme
Make customisations survive updates
  1. Create a child theme

    Make a folder in wp-content/themes named after your theme plus -child, with a style.css and functions.php (see the code below). Activate it under Appearance > Themes.

  2. Move template edits

    Copy any edited file, such as header.php, into the child theme at the same path. The child version is used instead of the parent's.

  3. Move tracking into a plugin

    Install a header and footer scripts plugin and paste the snippet there, or load it through a small custom plugin. Code in a plugin is untouched by theme updates.

  4. Use Additional CSS for styles

    Move CSS to Appearance > Customize > Additional CSS. Note this is stored per theme, so check it after a theme switch.

Child theme style.css (replace Template with your parent theme folder name)css
/*
Theme Name: My Theme Child
Template: my-theme
Version: 1.0.0
*/
Child theme functions.php: load the parent stylesphp
<?php
add_action( 'wp_enqueue_scripts', function () {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
} );
Small plugin that prints a tracking snippet in the headphp
<?php
/**
 * Plugin Name: Site Tracking Snippets
 */
add_action( 'wp_head', function () {
    ?>
    <!-- Paste your snippet here -->
    <?php
}, 1 );
Where your code lives

Edits in the parent theme

  • Snippet pasted into header.php
  • Theme update replaces the file
  • Tracking stops without any warning

Code outside the theme

  • Snippet in Tag Manager or a plugin
  • Template edits in a child theme
  • Updates leave your code intact

How to confirm it's fixed

After moving your code
  • View source shows your tag or GTM container exactly once
  • Network tab shows hits to GA4 and each ad platform you use
  • A test form submission or test checkout fires the conversion event in Tag Assistant or DebugView
  • The child theme is active under Appearance > Themes
  • Custom styles and template changes look the same as before
  • Old snippets are removed from the parent theme

How to prevent it happening again

A safer update routine
  1. Before

    Take a backup and note which tags and forms matter most.

  2. Update on staging

    Apply the theme update on a staging copy first and test forms and tracking.

  3. Update live

    Update production once staging passes.

  4. Straight after

    Re-run a test lead and check that tags fire.

Never edit a parent theme directly. Keep a short list of what you customised and where it lives, so anyone updating the site knows what to re-test. If you use a premium theme with auto-updates, consider turning them off for the theme and updating by hand after a staging test.

How FunnelGuard handles this

FunnelGuard detects this today. It notices when your theme changes and checks the tracking contracts, meaning the hits your journeys are supposed to send to GA4, Google Ads, Meta and the other platforms you use. If a theme change is followed by missing tracking, you get one alert with a screenshot and a likely cause.

A robot visitor runs your real journeys on a schedule, from the EU or the US. A failure is re-checked from a second region before alerting. Test traffic is marked with utm_source=funnelguard and fg_test=1. The Free plan covers 1 site and 2 journeys with daily checks and no card, and paid plans have a 3-day free trial.

Questions people ask

Why did my tracking stop after a WordPress theme update?

The update replaces the theme's files, so any snippet you pasted into header.php or footer.php is deleted. Check the page source for your measurement ID. If it is missing, restore the code and move it into Tag Manager, a plugin or a child theme.

Does updating a WordPress theme delete my customisations?

Yes, if you edited the parent theme's files directly. Those files are replaced on update. Settings saved in the database, such as Customizer options, usually survive, but edited PHP, template and CSS files do not.

How do I keep my changes when I update a WordPress theme?

Put edits in a child theme, a small custom plugin or Google Tag Manager instead of the parent theme. Parent theme updates then cannot touch them. Test on a staging copy before updating the live site.

Where should I put my Google Analytics code in WordPress so updates don't remove it?

Use Google Tag Manager or a header and footer scripts plugin, or load the snippet from a small plugin using the wp_head hook. Avoid pasting it into header.php of the parent theme.

Can I recover code lost in a theme update?

Yes, if you have a backup from before the update. Restore the old theme folder to a temporary location, copy your edits out, and place them in a child theme or plugin. Without a backup, you may need to rebuild the snippet from your analytics or ad account.

Do I need a child theme if I only add CSS?

Not always. CSS added in Appearance > Customize > Additional CSS is stored in the database and survives updates. It is tied to the active theme, so check it if you switch themes.

How can I tell quickly if a theme update broke my conversion tracking?

Run a test conversion after each update and watch for the event in Tag Assistant or GA4 DebugView. FunnelGuard can also do this on a schedule by running your journeys and checking the tracking hits.

Does FunnelGuard catch this?

Detected

FunnelGuard checks for this today.

How: Theme change + tag contracts.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.