Get the free theme
View Categories

How to Add Google Tag Manager to WordPress Without a Plugin

3 min read

Google Tag Manager gives you 2 snippets to install: one for the <head> and one for the <body>. You can add both without a plugin by editing your theme, but editing theme files means your changes can be lost on the next theme update. A cleaner way is a theme that gives you head and body code boxes, which is what Loupely Canvas does.

Where each snippet goes

  • The <head> snippet is the container script. It loads Tag Manager and does the actual work, and it belongs as high as possible in the document head.
  • The <body> snippet is a <noscript> fallback for visitors who have JavaScript turned off. Google places it right after the opening body tag.

Adding them in Loupely Canvas

Go to Appearance, Loupely Canvas. Paste the head snippet into the head code box, which prints in the document head on every page. Paste the noscript snippet into the body code box. Canvas prints the body box just before the closing body tag, so the fallback is on the page for the rare no-JavaScript visitor. The head snippet is the part that drives your tracking, so once it’s in place, Tag Manager is live.

Confirm it’s working

Publish, then use Tag Manager’s Preview mode, or your browser’s network panel, to confirm the container loads on the front end. Because Canvas renders your markup as written, the snippet you pasted is the snippet that ships.

<lc-toy:gtm-two-snippets>
<head> GTM container script </head> <body> GTM noscript fallback page content </body>
the container script loads as early as possible, so it goes in the head the noscript fallback must be the first thing inside the body