Custom codes missing from header.php
-
I had placed the google analytics code in header.php. But now it seems to be missing. As a result, google analytics is not able to detect the tag and data is not being sent to analytics. This problem has happened several times before. Why is this happening? What is the solution?
Attachments:
You must be
logged in to view attached files.
Hello,
The header.php file is part of the parent theme. Any direct modifications made to it will be overwritten whenever the theme is updated or reinstalled, which is why your Google Analytics code may disappear.
Instead of adding the tracking code directly to header.php, we recommend one of the following methods:
Add the Google Analytics or Google Tag Manager code using a dedicated plugin (recommended).
https://wordpress.org/plugins/insert-headers-and-footers/
If you want to edit the header.php file directly, then you need to copy the header.php file from the main theme to the child theme and then try adding the code in it.
Please check the article below for help: https://www.wpbeginner.com/beginners-guide/how-to-install-and-setup-google-tag-manager-in-wordpress/
Best Regards