How to add custom code to the header or footer
Most tracking codes, verification tags and chat widgets say “paste this in your header”. WPCode gives you a safe place to do that without touching your theme files.
- Time: About 5 minutes
- You need: A WordPress administrator login
- Updated:
Pasting code into your theme files works until the next theme update wipes it out. A snippet plugin keeps your codes in one place, survives updates and is easy to undo. The free WPCode plugin (formerly called Insert Headers and Footers) is the one I use.
Before you start
- The exact code from the official source: Google, Meta, your chat or booking tool. Never code from an old email or a random article.
- Know where it goes. The instructions usually say head (header), right after the body tag or footer.
- Is it Google Analytics or the Meta Pixel? Follow the Analytics guide or the pixel guide, which cover easier options.
Step 1: Install WPCode and open Header & Footer
Install the free WPCode plugin from Plugins > Add Plugin (see how to add a plugin). Then go to Code Snippets > Header & Footer.

WordPress 7.1 with WPCode: Code Snippets, then Header & Footer. Step 2: Paste head code into Header
Code that belongs in the <head> goes in the Header box: Google tags, verification meta tags, the Meta Pixel and most tracking codes.

WordPress 7.1 with WPCode: Header, Body and Footer boxes. Step 3: Use Body only when asked
The Body box is for code that must come right after the opening <body> tag. The most common example is Google Tag Manager’s second (noscript) code.
Step 4: Put widgets in Footer
Chat widgets, booking pop-ups and most other scripts can go in the Footer box. They load last, so they don’t slow down the top of your page.
Step 5: Save and test
Click Save Changes. Open your site in a private window, check the homepage and contact page, and use the vendor’s test tool (Google Tag Assistant, Meta Test events) to confirm it’s working.
If something breaks: delete the code you just added and save again. The site goes back to how it was.
Keep the list tidy
Add a comment above each code saying what it is, like <!-- Meta Pixel -->, so anyone can tell later. Remove old chat widgets, duplicate pixels and tools nobody checks anymore: every script slows your site a little.
Quick answers
Is it safe to paste code into my site?
Code from Google, Meta or a well-known tool is fine. Never paste code you don’t recognize, and send me anything that touches checkout, forms or payments first.
My theme has its own box for scripts.
That works too, but the code is lost if you change themes. WPCode keeps it no matter which theme you use.
Official help pages
- WPCode: Using the Global Header & Footer settings (opens in a new tab)
- WordPress.org: WPCode, Insert Headers and Footers plugin (opens in a new tab)
Checked against these pages on November 3, 2026.
Related guides

How to add Google Analytics to WordPress
Add Google Analytics 4 to WordPress with Google’s Site Kit plugin or by pasting the Google tag with WPCode. Real WordPress 7.1 screenshots.

How to add the Meta Pixel to WordPress
Add the Meta (Facebook) Pixel to WordPress with Meta’s official plugin or by pasting the base code with WPCode. Real WordPress 7.1 screenshots.

How to verify your WordPress site in Google Search Console
Verify a WordPress site in Google Search Console: add a URL-prefix property, paste the HTML tag into WPCode’s Header and click Verify. With screenshots.