I’m having trouble with the HubSpot plugin on my WordPress site. It’s tracking all pages, but I really want to stop it from monitoring one particular page. I attempted to add some code in my theme’s footer:
<?php
if (!is_page('my-shop-page')) {
// Insert HubSpot tracking code here
}
?>
Even after implementing this, the HubSpot script still appears on the page I intended to exclude. The page slug in question is ‘my-shop-page’.
Can anyone suggest a solution to properly exclude this page from being tracked? I would greatly appreciate any help!
hey alice45, have u tried using a plugin like ‘code snippets’ to add custom php? it’s easier than messing with theme files. you could try this:
add_action('wp_enqueue_scripts', function() {
if (is_page('my-shop-page')) {
wp_dequeue_script('hubspot-tracking');
}
});
this shud work if hubspot’s script is properly enqueued. good luck!
I’ve encountered this issue before, and a solution that worked for me was utilizing WordPress’s template_redirect hook. This method is quite effective and doesn’t require modifying your theme files. Here’s what you can do:
Add the following code to your functions.php file or a site-specific plugin:
add_action('template_redirect', 'disable_hubspot_on_specific_page');
function disable_hubspot_on_specific_page() {
if (is_page('my-shop-page')) {
add_filter('hubspot_disable_tracking', '__return_true');
}
}
This code checks if the current page is your shop page and, if so, disables HubSpot tracking using their built-in filter. Remember to replace ‘my-shop-page’ with your actual page slug.
After implementing this, clear your site’s cache and HubSpot’s tracking should be disabled on that specific page. If issues persist, you might need to contact HubSpot support for further assistance.
I’ve dealt with a similar issue before, and I found that using WordPress hooks can be more reliable than modifying theme files directly. Here’s what worked for me:
Add this code to your theme’s functions.php file or a custom plugin:
add_action('wp_head', 'remove_hubspot_from_specific_page', 1);
function remove_hubspot_from_specific_page() {
if (is_page('my-shop-page')) {
remove_action('wp_head', 'hubspot_tracking_code');
remove_action('wp_footer', 'hubspot_tracking_code');
}
}
This approach hooks into WordPress earlier in the loading process and removes the HubSpot tracking actions specifically for your shop page. Make sure to replace ‘my-shop-page’ with your actual page slug.
If this doesn’t work, double-check that HubSpot is actually using these hook names. You might need to inspect your page source to find the exact hook names HubSpot is using and adjust accordingly.
Remember to clear your cache after making these changes. Hope this helps!