Note: “Add Google Analytics (or any code) to WordPress” was originally posted on the Racine WordPress Meetup website.
There are many ways to insert codes like Google Analytics to your WordPress website. The method you choose will depend on your level of expertise and the plugins and theme that you are currently using.
Methods for adding Analytics to WordPress
Like most tasks in WordPress, there are many ways to achieve what you need. You could use your theme, a plugin, or edit your theme manually. Generally, adding code with a theme or a plugin is considered easy to accomplish, while editing your theme should be left to advanced WordPress users.
Using a reliable plugin to add code is the easiest solution
- Add code to WordPress using a plugin (easy to intermediate)*
- Add code to WordPress by editing your theme code (advanced)
Plugins to add code to WordPress
I’ve made a list of well-maintained and supported WordPress plugins that allow you to add code to your website.
- Adding code with the GeneratePress premium plugin
- Adding code with “Simple Custom CSS and JS”
- Adding code with Beaver Builder
- Adding Google Analytics with MonsterInsights
- Adding Google Analytics and Tag Manager with Google Site Kit
- Adding Google Analytics with RankMath
- Adding code with “Insert Headers & Footers”
Adding Executable PHP to WordPress
If you need to run PHP in WordPress, then make sure that the solution you choose works on more than just Google Analytics. Some plugins, like GeneratePress Premium allow for executable PHP. (You will, however, need to use the GeneratePress theme.)