Code Snippets Extension & WPCode

I already have WPCode (lite) installed on my sites and have code in place in the header area for Google Analytics plus a couple of code snippets.
Now, should I delete the the code snippet in WPCode and place it into the Code Snippets Extension instead?
I was using WPCode as it provided both code snippets and headers/footers code. If I move the code snippets to the extension, do I keep WPCode, or is there something better for the GA script?
Thanks!

1 Like

Hey @Gary_Petro

Sure, you can move the snippet for GA to the Code Snippets extension. When you use the “Execute on Child Sites” options, when saving & executing a snippet, the snippets functions essentially as if you saved it in the functions.php of the active theme.
image

The big advantage of using the Code Snippets extension is that you can easily enable or disable snippets in bulk on a large number of child sites.

However, in the specific case of GA code snippets, keep in mind that you will naturally have to use a different Code Snippet for each child site due to the required nature of the unique identifiers present in the script.

Sorry but I am a bit confused.
I thought that the GA code needed to go into the “Global Header” section? I don’t see a way to do that in the Code Snippets Extension.

And, If I am going to add it in this way, do I need to have a child theme installed?
Thanks.

Google Analytics code can be inserted in the functions.php file using the Code Snippet extension, but a WordPress action wp_head has to be used.

You can find an example of such code in this Gist: Adding Google Analytics script to functions.php file · GitHub

If you are adding anything in the functions.php file, then a child theme is effectively a requirement because a theme update will otherwise overwrite the functions.php file and erase any custom additions to it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.