Content management systems
Add Loogika to WordPress
WordPress has no built-in setting for header code. You add the Loogika tag with a plugin such as WPCode, or through the functions.php or header.php file of your theme. All four methods on this page load the script on every page of the site.
Last updated .
What do you need before you start?
Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own site ID in place of YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
Every method works on a self-hosted WordPress.org site. WordPress.com sites must be on a paid plan, because the Free plan cannot install plugins.
How do you add Loogika with the WPCode plugin?
WPCode is the method we recommend. The tag survives theme updates, and it works together with page builders.
- Go to Plugins, then Add New, and search for WPCode. Install the plugin and activate it.
- Go to Code Snippets, then Header & Footer. Older versions list it as Insert Headers and Footers under Settings.
- The Header box takes the tag. Finish with Save Changes.
How do you add Loogika through functions.php?
Use a child theme when you edit theme files. A theme update replaces the files of the parent theme, and your changes disappear with them.
- Go to Appearance, then Theme File Editor. With a block theme the editor sits under Tools.
- Open the
functions.phpfile of your child theme. - Add the code below at the end of the file, replace
YOUR_SITE_IDand save.
function loogika_add_tracking_script() {
?>
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
<?php
}
add_action( 'wp_head', 'loogika_add_tracking_script' );
Can you paste the tag into header.php?
Yes, on a classic theme. Open header.php in the Theme File Editor and paste the tag just before the closing </head> tag.
Block themes have no header.php. They have been the WordPress default since Twenty Twenty-Two and build the header from block templates. Use WPCode, functions.php or your own plugin on those themes.
How do you add Loogika with your own small plugin?
A plugin with one file keeps the tag in place when you change themes, and you never touch a theme file.
- Use SFTP or a file manager plugin to make a new folder at
/wp-content/plugins/loogika-analytics/. - Create the file
loogika-analytics.phpin that folder with the content below, and replaceYOUR_SITE_ID. - Go to Plugins in WordPress and activate Loogika Analytics.
<?php
/**
* Plugin Name: Loogika Analytics
* Description: Adds the Loogika tracking script to every page
* Version: 1.0
*/
function loogika_add_tracking_script() {
?>
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
<?php
}
add_action( 'wp_head', 'loogika_add_tracking_script' );
How do you check that Loogika is installed?
Load your site in a fresh browser tab and visit a few pages. The pageviews show up in the Loogika dashboard within a few seconds.
If nothing arrives, open the page source and look for script.js?siteId=. A missing tag on a WordPress site is usually a cached page, so work through the list below.
Why does WordPress not send data to Loogika?
| Cause | Fix |
|---|---|
| A caching plugin serves old pages | Purge the cache in WP Super Cache, W3 Total Cache, LiteSpeed Cache or the plugin you run. Purge your CDN cache as well, for example Cloudflare |
| A script optimiser delays or rewrites the tag | Exclude app.loogika.com from JavaScript optimisation and from delayed JavaScript in WP Rocket, Perfmatters, FlyingPress, Autoptimize, LiteSpeed Cache or SG Optimizer |
| A page builder strips the tag | Add the tag with WPCode. The custom HTML blocks in Elementor, Divi, WPBakery and Beaver Builder clean up HTML and can remove attributes |
| A security plugin blocks external scripts | Add app.loogika.com to the allowlist in Wordfence, Sucuri or a similar plugin |
| The site runs on the WordPress.com Free plan | Upgrade to a paid plan and use the WPCode method |
Script optimisers often drop data attributes when they rebuild a script tag. The Loogika tag carries the site ID in the address for that reason, so it keeps working after such a rewrite.
Does the tag also track a WooCommerce shop?
Yes. The tag records pageviews on shop pages like on any other page. The WooCommerce guide shows how to send purchases and add-to-cart clicks as events.