Header and footer code for WordPress that stays with your site

Adminkeep adds Appearance → Header & Footer Code: three boxes for the snippets services ask you to paste into your site. Analytics tags, Google Tag Manager, site verification, a chat widget. They belong to the site rather than the theme, so a theme update or a new theme doesn't take them with it.

free · Appearance → Header & Footer Code · classic and block themes

Header & Footer Code screen under Appearance with Head, Body open and Footer code boxes
Three boxes: Head, Body open and Footer, each in WordPress's own code editor.

Three boxes, where snippets ask to go

A service's install instructions nearly always name one of three places. There is one box for each, so you paste the snippet where it says and nowhere else.

Head

Printed near the top of <head>, before your theme's stylesheets and scripts. For the Google tag, Tag Manager's main snippet, and the meta tags that prove the site is yours to Search Console, Bing or Pinterest.

Body open

Printed straight after <body> opens, on themes that support it (current ones do). Tag Manager asks for its <noscript> fallback here.

Footer

Printed at the end of the page, after WordPress's own footer scripts. For chat widgets, and scripts that don't need to run first or expect a library such as jQuery to be loaded already.

Kept with the site, not the theme

Pasting a snippet into header.php works until the theme updates and overwrites the file. Here the code is kept in a site option that belongs to Adminkeep, and printed by WordPress's own hooks.

Prints on every theme

Classic or block, updated or replaced: whichever theme is active, the three boxes print in the same places.

Front end only

Nothing is added to the admin, the login page, feeds or the REST API. A snippet that misbehaves can't lock you out of the screen where you fix it.

Who changed it, and when

Under each box: "Last changed by" a name, or WP-CLI, and the date. When the tracking numbers jump, you can see whether someone touched the tags.

Kept when switched off, or deleted

Switching the feature off stops the code printing; switch it back on and it returns. Deleting the plugin keeps it too, unless you ask Adminkeep to delete its data.

Printed exactly as you saved it

A tracking snippet stops working if anything rewrites it, so nothing does. What you save is what the page gets, character for character. That is also why the screen is kept to the people WordPress already trusts with raw HTML.

  • Administrators who may post unfiltered HTML. Editing needs both manage_options and unfiltered_html. On multisite that means super admins only, and with DISALLOW_UNFILTERED_HTML set, nobody. Code already saved keeps printing.

  • Up to 64 KB a box. A snippet from an analytics or chat service is a few kilobytes. For anything bigger, upload the script as a file and load it with <script src="…">.

  • A refused save loses nothing. The screen saves without reloading the page. If a box is too large, or the database won't take the change, it says why and leaves all three boxes as you typed them.

  • Broken markup shows on the site. Paste snippets as the service gave them. If a page looks wrong after a save, open the screen (the code doesn't print in the admin) and fix or clear the box.

Styles go in the sibling feature: Custom CSS keeps site-wide CSS through theme changes the same way, and refuses HTML so a script can't slip in there.

From the command line, or over REST

With WP-CLI, wp adminkeep code get prints one box byte for byte, so it can go straight into a file and back. wp adminkeep code set replaces one box from a file or from standard input, and leaves the other two alone.

wp adminkeep feature enable header_footer_code
wp adminkeep code set head analytics.html
cat gtm-noscript.html | wp adminkeep code set body
wp adminkeep code get footer > footer.html

Roll the same tags out to every site you run, or keep them in version control. Clearing a box that holds code asks first; --yes skips the question. With --user, that user needs the same two permissions as the screen.

WP-CLI reference →

No shell? Since 2.2.0 the boxes can be read and saved at /wp-json/adminkeep/v1/header-footer-code with a WordPress application password. Send only the boxes you want to change; the others are kept, and an empty string clears one. The same permissions and limits apply as on the screen.

curl -u 'admin:XXXX XXXX XXXX XXXX XXXX XXXX' \
  -H 'Content-Type: application/json' \
  -d '{"head": "<meta name=\"google-site-verification\" content=\"XXXX\">"}' \
  https://example.com/wp-json/adminkeep/v1/header-footer-code

REST API reference →

Turn it on in a minute

  1. 01

    Install Adminkeep from Plugins → Add New Plugin (search "Adminkeep") and activate it.

  2. 02

    Go to Settings → Adminkeep and switch on Header & Footer Code, in the Appearance group.

  3. 03

    Open Appearance → Header & Footer Code, paste each snippet into its box and press Save code.

How to add Google Tag Manager to WordPress

Which box each of the two GTM snippets goes in, how to check it is live, adding GA4, and the no-plugin route through a child theme.

Read the guide →

Header & Footer Code docs

Where each box prints, who can edit it, the size limit, what happens on a refused save, the REST API route and the commands.

Read the docs →

Custom CSS that survives a theme switch

The sibling feature for styles: one site-wide stylesheet, kept when you change themes, with a live editor that restyles the page as you type.

Custom CSS, in detail →

Why WordPress custom CSS disappears

The same problem for CSS: Additional CSS belongs to the theme, so it stays behind when you switch.

Read the guide →

Switch on what you need. Forget the rest.

A free WordPress plugin — GPL, instantly reversible, and updates come to you.

Type to search the whole site.