- This topic has 12 replies, 3 voices, and was last updated 4 years, 8 months ago by
Leo.
-
AuthorPosts
-
February 21, 2018 at 2:26 am #501772
Edin
Hello,
What would be the preferred way if I wanted to add tracking code (one part in the header, the other part below the body tag) to specific pages or posts only?
Like for example the FB tracking code and event tracking that I only want for a few pages of my site.
Thanks,
EdinFebruary 21, 2018 at 9:02 am #502118Leo
StaffCustomer SupportHi Edin,
Something like this should help: https://docs.generatepress.com/article/using-hooks-conditional-tags/
Let me know.
February 21, 2018 at 11:17 am #502251Edin
Thank you Leo.
So, if I wanted to add a tracking code to pages 55, 56, 57 in the header, I add this code to the wp_head hook:
<?php if ( is_page(55, 56, 57) ) : ?> <script>Tracking Script</script> <?php endif; ?>
Right?
I’d have to check “Execute PHP”, would that mess up code that’s already in there but is no php?
Thanks,
EdinFebruary 21, 2018 at 3:22 pm #502366Leo
StaffCustomer SupportYup code looks good.
Nope it won’t mess with the code without PHP π
September 17, 2018 at 8:12 am #679328Edin
I’ve had this working with one page since I started this thread.
Today, however, I wanted to add another page, but for some reason, the tracking code only fires on the first specified page number.
<?php if ( is_page(7134, 6891) ) : ?> <!-- Facebook Pixel Code --> <script> FB code </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=x" /></noscript> <!-- End Facebook Pixel Code --> <?php endif; ?>
So the FB-Pixel only fires on post 7134, NOT on post 6891. Any idea why?
Thanks,
EdinSeptember 17, 2018 at 9:11 am #679377David
StaffCustomer SupportTry using the new Elements module for Hooks:
https://docs.generatepress.com/article/hooks-element-overview/
You can remove the conditional PHP now and use the Display Rules it provides.
September 17, 2018 at 9:16 am #679385Edin
Thanks David.
Can you point me to the article that describes how to switch from the “old” hooks system to the new elements module for Hooks? (I’ve seen it somewhere, but can’t find it again)
September 17, 2018 at 9:24 am #679398Edin
Also, can I use both systems at the same time?
September 17, 2018 at 9:31 am #679401Leo
StaffCustomer SupportShould be in our documentation page:
https://docs.generatepress.com/article/moving-hooks-page-headers-to-elements/Technically you can use both but I don’t see any advantages of doing that though.
Best to use the new one π
September 17, 2018 at 11:04 am #679472Edin
I started to migrate from the GP-Hooks module to the new Elements module.
Problem is, the GP-Hooks module link disappears from the dashboard as soon as “Elements” is activated. Which makes it kind of hard to copy over the code …
September 17, 2018 at 11:37 am #679493Leo
StaffCustomer SupportYou can still access legacy hooks module by clicking the Legacy Hooks button on the Elements listing page.
Once it’s empty in there the button will disappear.
Let me know if this helps π
September 17, 2018 at 11:42 am #679500Edin
Perfect! Thank you!
September 17, 2018 at 12:19 pm #679529Leo
StaffCustomer SupportNo problem π
-
AuthorPosts
- You must be logged in to reply to this topic.