How do you add Google Analytics tracking code in a custom theme of WordPress?

  1. Get your Google Analytics tracking code: Log in to your Google Analytics account and go to the Admin section. Under the Property column, click on Tracking Info, and then Tracking Code. Copy the code that appears in the Global Site Tag (gtag.js) box.
  2. Open the WordPress theme editor: Log in to your WordPress website and go to the Appearance section. Click on Theme Editor to open the theme editor page.
  3. Open the header.php file: In the theme editor, find the header.php file on the right-hand side of the screen. This file controls the header section of your website, where you want to add the Google Analytics tracking code.
  1. Paste the tracking code: Scroll down to the bottom of the header.php file and paste the Google Analytics tracking code just before the closing </head> tag.
  2. Save the changes: Click on the Update File button to save the changes.

That’s it! Your WordPress custom theme is now set up to track visitors using Google Analytics. It may take a few hours for data to start appearing in your Google Analytics account.

Leave a Comment