-
simon
Hi there!
I need to insert code into my Child Theme in the header.
It’s for an affiliate’s tracking code.
Their instructions say go to Appearance – Theme File Editor and insert in the Theme Editor
But this does not appear in the Child Theme.
So do I change to the GP theme and enter it there?
And if so, what happens when the GP theme updates (a reason I created the child was to avoid losing customisations on GP updates).
Cheers Simon
-
Hi there,
Are you referring to
wp_head
hook?
https://docs.generatepress.com/article/wp-head/If so the simplest way is to use a hook element:
https://docs.generatepress.com/article/block-element-hook/It’s designed for things like this.
If you still prefer to function instead then you would need to use this snippet inside the function.php of the child theme: https://docs.generatepress.com/article/using-hooks/
Let me know if this helps 🙂
-
simon
Hi Leo
Ahh – right – I forgot about hooks.
1. What are the relative merits of the two methods?
My number one concerns are speed and reliability.
The current need is for inserting tracking for an affiliate program but I will also have other code, like Google Analyitics, and SEO monitoring code so it would be good to ensure the method is easy and fast.
What’s the diff between the two?
2. If I use the php method (and I have done some other things with php so I am comfortable with the general idea) am I right in saying I set up an Element with the code in it and then update the php with the code shown at https://docs.generatepress.com/article/using-hooks/ – amended for the name of the element?
Cheers Simon
-
1. I don’t believe the two methods will have a noticeable performance difference – you can always try both and run speed tests to compare.
2. If you use the function method then it would need to be added using one of the methods here and not through elements: https://docs.generatepress.com/article/adding-php/
I would say the best method for you would be to use elements 🙂
-
simon
Hi Leo
So if I use the Elements, am I right in saying its the same process as described here for Google Analytics
And I just use the code provided by my affiliate program:
<!– GetYourGuide Analytics –>
<script async defer src=”https://widget.getyourguide.com/dist/pa.umd.production.min.js” data-gyg-partner-id=”A8KZ1HS”></script>
Then, if I end up having multiple of these elements for other things Google analytics etc etc I just set up multiple of these elements – is that correct?
Finally, if I have multiple of these scripts, how do I decide what priority to make each one or do I just leave them all at 10?
Thanks for your patience in helping me with this!
Simon
-
Alvind
Hi Simon,
If the script is to be placed in a common hook, you can combine them together in one element. This way, you can adjust the priority more easily, with the top one loading at a higher priority.
- You must be logged in to reply to this topic.