To add Google Analytics, Tag Manager or other code to WordPress without editing theme files, use a header and footer plugin. In the free ExtenderX plugin, open Custom Code, add a snippet, paste the code and choose Header, Body Open or Footer. It survives theme updates, works on block themes, and you can switch any snippet off without deleting it.
Why not edit the theme?
- Theme updates overwrite
header.phpandfooter.php. - Switching themes silently drops your tracking.
- Block themes don't have those files at all.
- One typo in a PHP template can take the site down.
A plugin keeps your code separate and lets you toggle it.
Add a snippet with ExtenderX
- Install and activate ExtenderX.
- Go to ExtenderX → Custom Code and click Add Snippet.
- Name it (for example "GA4") and paste the code.
- Choose where it goes:
- Header — inside
<head> - Body Open — right after
<body> - Footer — before
</body>
- Header — inside
- Save. Disabled snippets stay saved but stop running.
Where common codes go
| Code | Location |
|---|---|
| Google Analytics (gtag.js) | Header |
| Google Tag Manager — script | Header |
| Google Tag Manager — noscript | Body Open |
| Meta (Facebook) Pixel | Header |
| Google AdSense auto ads | Header |
| Site verification meta tag (Google, Bing, Pinterest) | Header |
| Chat widgets | Footer |
| Custom CSS | Header (or a CSS snippet) |
After saving, check the code is live with the service's own tester — Google Tag Assistant, Meta Pixel Helper, or the verification button in Search Console.
Which plugin should you use?
| ExtenderX | WPCode | Header Footer Code Manager | Code Snippets | |
|---|---|---|---|---|
| Header / footer scripts, free | Yes (+ Body Open) | Yes | Yes (+ before/after content) | — (HTML via shortcodes) |
| CSS & JavaScript snippets, free | Yes | Yes | Yes | Pro |
| PHP snippets, free | Pro | Yes | — | Yes |
| Load on specific pages, free | Pro | Yes (smart conditions in Pro) | Yes | Pro |
| Snippet library | — | Yes | — | Community cloud |
| Also an accessibility toolbar, dark mode, animations, maintenance mode | Yes | — | — | — |
Sources: WPCode, Header Footer Code Manager, Code Snippets, as of October 25, 2026. Disclosure: WPXERO makes ExtenderX (version 1.10.0).
Our honest take: if code is all you need, and especially if you write PHP snippets, a dedicated code plugin does more for free. If you'd otherwise install separate plugins for tracking codes, an accessibility toolbar, dark mode, maintenance mode and block animations, ExtenderX replaces all of them with one dashboard — and a disabled feature adds zero CSS and JavaScript.
Pro: PHP, conditions and scheduling
ExtenderX Pro adds PHP snippets, conditional display for specific pages or post types, and scheduling, starting at $19.99 a year.
Keep your scripts tidy
- Remove what you don't use. Old pixels from past campaigns still load on every page.
- Use one tag manager instead of five separate tracking codes.
- Check your consent setup. If you need a cookie banner, tracking scripts should respect it.
- Label every snippet so you know what it does a year from now.