Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Uplift › Facebook pixel
New Landing › How can we help? › Themeforest Theme Support › Uplift › Facebook pixel
- This topic has 7 replies, 3 voices, and was last updated 7 years by David Martin – Support.
-
Posted in: Uplift
-
October 9, 2016 at 4:52 am #295364
Hi guys,
would like to add the new Facebook pixel to my site without any plugin.
I am using your child theme, but there is not header.php file in there where I could include the pixel code.Can you please advise how to / what to add to the child theme to be able to have a header.php file (or similar)?
ThanksOctober 10, 2016 at 3:35 pm #295526Hi,
Never tried Facebook Pixel but try to add the code below to the functions.php of your child theme.
add_action('wp_head', 'facebook_pixel_wp_head'); function facebook_pixel_wp_head(){ //Close PHP tags ?> <!-- Facebook Pixel Code --> <script> !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n; n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window, document,'script','//connect.facebook.net/en_US/fbevents.js'); // Insert Your Facebook Pixel ID below. fbq('init', 'FB_PIXEL_ID'); fbq('track', 'PageView'); </script> <!-- Insert Your Facebook Pixel ID below. --> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=FB_PIXEL_ID&ev=PageView&noscript=1" /></noscript> <!-- End Facebook Pixel Code --> <?php //Open PHP tags }
this is just an example replace the code inside by your facebook pixel code.
Let us know if it worked.
-Rui
October 11, 2016 at 2:46 am #295637Hi Rui,
I am comfortable with the FB Pixel, I would just need one thing:
– THE FB pixes should be place in the header.php file just before the close </head> tag.However I don’t have a header.php file in my child theme and don’t know how to create one.
Can you please put me in the right direction?October 11, 2016 at 9:33 am #295650The function above is better then adding it to an actual file, the code above will automatically add the code using the WordPress action
wp_head
with is called within the header.php file. So it saves you keeping the child theme template file updating with each release.October 11, 2016 at 12:18 pm #295702Hi David,
okay, thanks I will try tonight.
Just one question:
I thought that if I put any custom stuff in the child theme, I don’t need to worry about anything when updating the themes…
I thought the child theme is for this reason… Or am I wrong or just missing something?October 11, 2016 at 12:24 pm #295705Lot’s of people have the perception that using a child theme they don’t need to worry with updates and that is not 100% true because if we change a file that you also customize things can break if you don’t copy the new changes across.
The function I provided will add the code to the head of the page(that’s what FB asks), so give it a try.
-Rui
October 16, 2016 at 9:51 am #296711This reply has been marked as private.October 18, 2016 at 12:19 pm #297164You would create new new functions using the template code Rui provided. An example is below, you then add your code to the two new functions.
add_action('wp_head', 'gtm_pixel_wp_head'); function gtm_pixel_wp_head(){ ?> <!-- ADD YOUR CODE HERE --> <?php }
add_action('sf_before_page_container', 'gtm_noscript_pixel_wp_head'); function gtm_noscript_pixel_wp_head(){ ?> <!-- ADD YOUR CODE HERE --> <?php }
Thanks,
David. -
Posted in: Uplift
You must be logged in to reply to this topic.