-
AuthorPosts
-
February 17, 2015 at 10:14 pm #397844
Hi, I need to insert a facebook campain scrip/code bettwen <head> and </head>.
How can I do it?Thanks for your answer.
- This topic was modified 9 years, 9 months ago by Freepress.
February 17, 2015 at 10:46 pm #397868Hi Daniel!
Add this to the bottom of your functions.php file.
add_action( 'wp_head', 'enfold_customization_custom_scripts' ); function enfold_customization_custom_scripts(){ ?> <script>(function() { var _fbq = window._fbq || (window._fbq = []); if (!_fbq.loaded) { var fbds = document.createElement('script'); fbds.async = true; fbds.src = '//connect.facebook.net/en_US/fbds.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(fbds, s); _fbq.loaded = true; } _fbq.push(['addPixelId', '1456847771268020']); })(); window._fbq = window._fbq || []; window._fbq.push(['track', 'PixelInitialized', {}]); </script> <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id=1456847771268020&ev=PixelInitialized" /></noscript> <?php }
Regards,
Elliott- This reply was modified 9 years, 9 months ago by Elliott.
February 18, 2015 at 1:49 am #397919Thanks for your help @Elliott !
February 18, 2015 at 4:27 pm #398233@Elliott
This looks exactly like what I need.
Am I correct in that there is “too much” code in your example?
As I understand it I should just add from script to noscript – the exact code that I get from Facebook.
Or did I miss something? ;)February 18, 2015 at 9:46 pm #398475Hi!
Add this to the bottom of your functions.php file.
add_action( 'wp_head', 'enfold_customization_custom_scripts' ); function enfold_customization_custom_scripts(){ ?> paste your facebook code here <?php }
And then replace the text with your facebook code.
Best regards,
ElliottMay 31, 2016 at 3:39 pm #640953Not to hijack this older post, but I have an additional question. I took over a website and in my Childtheme I have the functions.php file where I need to put the above code. However there is more code already there (I have no idea what it does).
I am unsure where to put this new Facebook code. For now I have put it at the bottom, just above the closing ?> tag that was already in the functions.php. Is this the way to do it, or did I make a mistake?
The code that is there is the following (see Private Content):
June 1, 2016 at 6:55 am #641257June 2, 2016 at 6:29 pm #642174It looks like it is working :-). Thanks!
-
AuthorPosts
- The topic ‘Adding facebook code into head’ is closed to new replies.