Keeping affiliate links working after a WordPress theme update
I've clicked through more broken affiliate links than I care to admit. The worst was the morning my AFFINGER5 parent theme pushed an update and the custom CSS behind my gold "check price" buttons vanished — the buttons stayed, the links went. Australian readers in Sydney and Melbourne didn't notice, they just bounced, and the commission went with them. Since then I've treated every theme update as a maintenance job with a checklist rather than a one-click button.
Most people assume affiliate links live in the post body where they're safe. Some do. Plenty of them live in template files, in a custom fields panel, inside a shortcode the theme supplies, or in a popup script a plugin injects. A theme update replaces template files and can quietly change the shortcode API underneath you, so links that worked on Monday can be dead on Tuesday. Here is the routine I actually run, from backup stage through to the final click test.
A note on who this is for: this blog targets Australia, and that matters more than it sounds. Links to Amazon.com.au, Bunnings, JB Hi-Fi or Kmart pay differently from their US equivalents, prices sit in AUD with 10% GST included, and the ACCC's expectations around endorsements and price claims are stricter than a generic disclosure line. The routine below is built to keep the links alive and the site honest.
What a theme update actually overwrites
A theme update replaces every file inside the theme folder with the new version. Anything stored in your database — posts, pages, Gutenberg blocks, images — survives untouched. Anything written into header.php, footer.php, single-post templates, demo sections or a theme options panel does not. Theme option panels usually reset to defaults on update, so a link you added through a theme-specific "custom styling" tab can vanish without warning.
Shortcodes and functions are the other trap. AFFINGER5 ships shortcodes for its demo and product blocks, and when a parent update renames or removes the underlying function, your post renders the raw shortcode text instead of a button. Worse case: if your child theme defines a function the parent now also defines, PHP throws a fatal "Cannot redeclare" error, the site shows a white screen, and every affiliate link on every post stops working simultaneously. I've watched that happen twice.
Then there is caching. A theme update often bumps the bundled jQuery version, which breaks sliders and popup plugins, and your CDN keeps serving stale HTML with old link parameters long after you fixed them. When a reader tells you "the link is broken", sometimes the link is fine and the page being served is nine days old.
Backups and a staging copy before I touch anything
I schedule UpdraftPlus backups of files and database to Google Drive, and I also export the database tables as a .sql file through phpMyAdmin. The child theme folder lives in a synced folder so I can see exactly what I changed. Restoring is the part people skip, so twice a year I deliberately break the staging site to confirm I can rebuild the main one. A backup you have never restored is only a hope with a filename.
The staging copy matters more than the backup. I duplicate the site to a staging subdomain or pull it down into LocalWP, run the update there, then click every link type: plain text link, button link, image link, Amazon product link, popup CTA. The Theme Check plugin and the PHP error log tell me about undefined functions that the front end hides. I always test on a real phone, because most of the traffic arriving from Australia is mobile and nothing teaches you that faster than a CTA sitting under a sticky header on a small screen.
I also keep a link inventory: a spreadsheet with the destination URL, network, affiliate ID, post ID and last click date. Networks credit sales on different windows — Amazon Associates, for example, ties a qualified sale to a click within 24 hours — so I note each window rather than guessing. The same sheet doubles as source documentation for my ATO records, since a sole trader needs to show where the income came from.
Moving links out of theme files and into one place
The durable pattern is to store affiliate data once and render it everywhere. I keep affiliate details in a small "Affiliate link" custom post type with fields for label, destination URL and rel attributes, then call it from posts with a shortcode. Post content lives in the database, so it survives theme updates, plugin swaps and even a full migration to a new host. If the theme dies, the database does not.
For recurring calls to action I use a Gutenberg reusable block, so one edit updates the button across every review post instead of thirty separate edits. The same shortcode handles the disclosure line, which means the ACCC-compliant wording about earning a commission appears consistently wherever a link appears, instead of once at the bottom of a page where nobody scrolls.
Google treats paid links differently from editorial ones. rel="sponsored nofollow noopener" with target="_blank" is the safe combination; plain nofollow on its own is not enough for affiliate links. Amazon Associates also has trademark rules that catch people out — you cannot use the Amazon logo or the word "Amazon" as your anchor text without approval, so my links read "Check price on Amazon.com.au" and nothing more aggressive.
Child theme habits that keep customisation intact
Every custom change I make lives in a child theme: a style.css with the template header line, and a functions.php that enqueues my own stylesheet. Editing the parent's style.css directly is the single most common way to lose work, because the next update replaces that file with no warning and no diff.
Custom CSS goes in the child theme stylesheet or the Customizer's own "Additional CSS" field, which is stored separately from theme files and usually survives. The theme's internal styling tab does not survive; my gold button background image pointing at a JB Hi-Fi product page disappeared exactly that way. I treat any styling stored inside the theme panel as temporary.
For PHP, I use hooks and filters rather than copying parent functions into the child theme. Filters such as the_content and shortcode helpers let me extend behaviour without redefining anything, and every function I declare carries a prefix so a future parent release cannot collide with it. When something breaks, I read the PHP error log before touching the browser cache, then purge LiteSpeed and Cloudflare so the fixed HTML reaches Australian readers on slower NBN and fixed wireless connections.
Redirects, cloaking and short links
The single most useful tool in my setup is a redirect table. In the Redirection plugin I map a short path such as /go/bunnings-tracker to the full network URL carrying my affiliate ID. When a network changes its URL format, or when I rotate my ID, I edit one row and every old link in every old post works again. Readers never see a long tracking string, and search engines see a clean internal path.
Cloaking deserves care. JavaScript-based cloakers break under ad blockers, can be flagged by affiliate networks, and leave a blank page when scripts are blocked — on Australian connections that is common enough to matter. A server-side redirect or a first-party landing page with a visible, dated disclosure works better. My wording states plainly that I earn a commission at no extra cost to the reader, which matches ACCC guidance on endorsements being clear, prominent and upfront.
Tracking parameters have to survive the trip. A redirect entry must carry ?tag= or the equivalent sub-ID, or the commission attaches to nobody. Shorteners that strip query strings will silently break attribution, and any short domain I use must not route through a hop controlled by another affiliate, because then I would be paying commission to the wrong person. One more Australian wrinkle: Amazon.com.au links only pay on Australian purchases, so a reader in Perth clicking a US Amazon URL earns me nothing.
Plugins, popups and other things that swallow clicks
Popups, exit-intent overlays, sticky CTAs and sliders are where clicks quietly disappear. A jQuery bump from a theme update can break the plugin entirely, leaving a button that renders but never registers a hit. If a link suddenly stops converting, I test it with overlays disabled before assuming the network changed something.
Ad blockers are everyday in Australia, and cashback-style browser extensions compete for the same referral. When an extension rewrites your tracker link, one of the two affiliate IDs gets paid and sometimes neither does, and some networks penalise duplicate referral IDs on the same click. I give each channel its own sub-ID so I can see which source produced the sale and which one got hijacked.
Mobile contexts cause their own failures. In-app browsers on iOS and Android can block window.open or handle target="_blank" differently, so the link appears to do nothing. And a fixed-position button that looked fine on a wide desktop monitor can land under the fold on a 6-inch phone, which is where most Australian readers are actually reading from.
The routine I run after every update and each quarter
The update itself takes about fifteen minutes once the preparation is done. Then I run a quarterly sweep to catch the slow decay: networks quietly changing URL formats, product pages disappearing from Amazon.com.au, and category links on retailer sites such as Bunnings or Kmart that have moved to a new URL structure. I also check the redirect log for a spike of 404s on /go/ paths, because a wave of those usually means a child theme function was overwritten or a plugin deactivated the shortcode.
These are the habits that keep the links working, in the order I apply them:
- Back up files and database to Google Drive before every update, and rehearse a restore twice a year.
- Run the update on staging first, then read the PHP error log rather than judging by the front end alone.
- Keep affiliate URLs in post content or a single shortcode, never inside template files.
- Use a child theme for custom CSS and PHP, and prefix every function you define.
- Route outbound links through a redirect table so one edit repairs every post at once.
- Apply
rel="sponsored nofollow noopener"and keep a visible disclosure above the link. - Click-test on a phone with popups and ad blockers off, then purge the CDN cache.
The payoff is boring and reliable. A link I publish on a Sunday still works in six months, whether the reader is in a Sydney suburb, a Melbourne flat or a café in Brisbane, and nobody — including me — has to log in at midnight chasing a dead button. That is the whole game: fewer surprises, fewer lost commissions, and content that keeps earning while I focus on the next piece.