Manage your WordPress site

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.
  1. 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.

    The WordPress menu with Code Snippets and Header and Footer circled
    WordPress 7.1 with WPCode: Code Snippets, then Header & Footer.
  2. 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.

    WPCode Header, Body and Footer boxes with Save Changes circled
    WordPress 7.1 with WPCode: Header, Body and Footer boxes.
  3. 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.

  4. 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.

  5. 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

Checked against these pages on November 3, 2026.