Documentation

WordPress

Add Loamly to your WordPress site

WordPress powers over 40% of the web, and Loamly integrates easily using either a plugin or direct theme editing. Choose the method that works best for your setup.

Using a plugin (recommended)

The easiest way to add Loamly to WordPress is with a header/footer plugin. We recommend WPCode (formerly Insert Headers and Footers):

  1. Go to PluginsAdd New
  2. Search for "WPCode"
  3. Install and activate the plugin
  4. Go to Code SnippetsHeader & Footer
  5. In the Header section, paste:
<script
  src="https://app.loamly.ai/t.js?d=yourdomain.com"
  defer
></script>
  1. Click Save Changes

Other plugin options

  • Header Footer Code Manager
  • Simple Custom CSS and JS
  • Any plugin that lets you add code to the header

Editing your theme

If you prefer not to use a plugin, you can add the script directly to your theme:

Method 1: Theme Customizer

Some themes include a "Custom Code" section:

  1. Go to AppearanceCustomize
  2. Look for Additional CSS/JS or Custom Code
  3. Add the Loamly script to the header section
  4. Publish your changes

Method 2: Edit header.php

Use a child theme

Direct theme edits will be lost when the theme updates. Always use a child theme or the plugin method for production sites.
  1. Go to AppearanceTheme File Editor
  2. Select your theme and open header.php
  3. Find the </head> tag
  4. Paste the script just before it
  5. Click Update File

Method 3: Using functions.php

Add this to your child theme's functions.php:

// Add Loamly tracking script
function add_loamly_tracking() {
  ?>
  <script
    src="https://app.loamly.ai/t.js?d=yourdomain.com"
    defer
  ></script>
  <?php
}
add_action('wp_head', 'add_loamly_tracking');

Verify installation

  1. Visit your WordPress site in a new browser tab
  2. Right-click → View Page Source
  3. Search for "loamly" to confirm the script is in the head
  4. Check your Loamly dashboard for the visit

WooCommerce tracking

If you use WooCommerce, you can track purchases by adding code to your theme or using the WPCode plugin:

// Add to functions.php or as a WPCode snippet
add_action('woocommerce_thankyou', 'loamly_track_purchase');

function loamly_track_purchase($order_id) {
  $order = wc_get_order($order_id);
  if (!$order) return;
  ?>
  <script>
  if (window.loamly) {
    window.loamly.event('purchase', {
      order_id: '<?php echo esc_js($order_id); ?>',
      total: <?php echo esc_js($order->get_total()); ?>,
      currency: '<?php echo esc_js($order->get_currency()); ?>',
      items_count: <?php echo esc_js($order->get_item_count()); ?>
    });
  }
  </script>
  <?php
}

Revenue attribution

With WooCommerce tracking, you can see exactly how much revenue each traffic source generates, including AI platforms like ChatGPT and Perplexity.