How to Install Digital Carbon Online in WordPress
This guide provides WordPress-specific installation instructions for the Digital Carbon Online tracking code, expanding upon our basic installation instructions in the FAQ. While the standard implementation works for most cases, this advanced approach offers better control over script loading and performance optimisation. For installation guides on other platforms or content management systems, please consult documentation specific to that platform.
Method 1: Direct Theme Implementation
Add this code to your theme’s footer.php
file just before the closing </body>
tag.
Please note: The code below uses example code, your specific code will be emailed to you once you’ve signed up and been been provisioned.
Example code snippet:
<?php
// Add this code snippet to your theme's footer.php
add_action('wp_footer', function() {
?>
<script defer id="theScript" type="text/javascript" src="https://HOST_NAME/SCRIPT.js"></script>
<script defer type="text/javascript">
theScript.addEventListener('load', function () {
wti_webco2.init(["YOUR_UNIQUE_AUTHENTICATION_CODE"]);
});
</script>
<?php
}, 99);
Method 2: Using WordPress Plugins
These instructions are for illustrative purposes, please follow the specific plugin’s own documentation.
Option A: WPCode Plugin
- Install and activate “WPCode” by WPBeginner
- Go to Settings > Insert Headers and Footers
- In the “Scripts in Footer” section, paste the code snippet you receive in your on-boarding email (example shown below).
<script defer id="theScript" type="text/javascript" src="https://HOST_NAME/SCRIPT.js"></script>
<script defer type="text/javascript">
theScript.addEventListener('load', function () {
wti_webco2.init(["YOUR_UNIQUE_AUTHENTICATION_CODE"]);
});
</script>
- Install and activate “Insert Headers and Footers“
- Create New Snippet
- Select “HTML” type
- Set location to “Footer”
- Paste the code above
- Save and activate
Installation Verification
- Clear your website cache
- Open your website in an incognito/private window
- Right-click > Inspect Element (or press F12)
- Go to the Console tab
- Check for the messages as described in our FAQ
- Verify that the script is loaded with ‘defer’ attribute
Troubleshooting Tips
- If using a caching plugin, purge all caches after installation
- If using a security plugin, ensure it’s not blocking the script
- Check if your theme already has a footer code implementation area
- Verify your authentication code is correctly formatted
- Test on multiple pages to ensure consistent loading
- Contact us at support [@] digitalcarbononline.co.uk for support
Best Practices
- Always backup your site before making changes
- Test on a staging environment first
- Use a child theme if modifying theme files directly
- Keep your authentication code secure