Archived topic
Which hook to use for just below the head tag?
5 replies · Started by Lee on October 18, 2021
Hi.
I want to add a Facebook Pixel event code which needs to go just below the </head> tag. Using Elements, which hook would be the correct one to use?
Thanks in advance!
Lee
Hi Lee,
There isn't a hook right below the closing </head>:
https://github.com/tomusborne/generatepress/blob/master/header.php#L19
Can you try the wp_head hook first? That's where Facebook Pixel code usually goes in from my understanding.
Let me know :)
Hi Leo.
I already have the base Pixel hooked into the wp_head via elements. I'm now trying to add a purchase event code and Facebook says the following:
- Place the event code on your order confirmation page or purchase completion page.
- Add the event code just below the </head> tag. This allows the event code to load along with the pixel code when the page loads.
Can you try this one instead?
https://docs.generatepress.com/article/wp_body_open/
If not, then you will need to:
1. Create a child theme:
https://docs.generatepress.com/article/using-child-theme/
2. Copy and paste the header.php file in the child theme folder:
https://github.com/tomusborne/generatepress/blob/master/header.php
3. Then add your code at the desired spot:
https://github.com/tomusborne/generatepress/blob/master/header.php#L19
Thanks Leo, really appreciate your help.
In addition to going just below the </head> tag, it also has to be on the Woocommerce order confirmation page with isn't available in Elements, but I've just found the following thread that worked for someone else, so I'll try that:
https://generatepress.com/forums/topic/gp-elements-displayed-on-the-woocommerce-confirmation-page/
Sounds good.