How can I disable a code from GTM on homepage? I want that code only on product pages.
Thank you
Webmasters Stack Exchange is a question and answer site for pro webmasters. It only takes a minute to sign up.
Sign up to join this communityHow can I disable a code from GTM on homepage? I want that code only on product pages.
Thank you
The easyest way not to display Google Tag Manager on Homepage is to check with php.
You can insert GTM in the header.php
file of your child-theme
like this:
<?php
if (!is_home() && !is_front_page()) {
echo 'your GTM code here';
}
?>
Will display GTM everywhere but on home (blog posts homepage) nor on front page (the static page you may have defined as the home of your wordpress).
Then if you only want it on product pages there are a bunch of possibilities since there are a lot of product pages types (category page, single product page...).
But if you want it to display only on a few product pages type you could choose to display it only IF it's the good page type.
<?php
if (is_product()) {
echo 'your GTM code here';
}
?>
You will find woocommerce conditional tags here : https://docs.woocommerce.com/document/conditional-tags/ where you will be able to choose on which condition you want your GTM to display or not.
Gael's answer is probably the best, but i just wanted to let you know that there's also a possibility of having the GTM container code, but not actually tracking the home page.
In that case, you just need to create a trigger, that would look like in the image attached.