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):
- Go to Plugins → Add New
- Search for "WPCode"
- Install and activate the plugin
- Go to Code Snippets → Header & Footer
- In the Header section, paste:
<script
src="https://app.loamly.ai/t.js?d=yourdomain.com"
defer
></script>- 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:
- Go to Appearance → Customize
- Look for Additional CSS/JS or Custom Code
- Add the Loamly script to the header section
- 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.
- Go to Appearance → Theme File Editor
- Select your theme and open
header.php - Find the
</head>tag - Paste the script just before it
- 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
- Visit your WordPress site in a new browser tab
- Right-click → View Page Source
- Search for "loamly" to confirm the script is in the head
- 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.