Tagged: , ,

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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.
    #397868

    Hi 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&quot; /></noscript>
    
    <?php
    }

    Regards,
    Elliott

    • This reply was modified 9 years, 9 months ago by Elliott.
    #397919

    Thanks for your help @Elliott !

    #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? ;)

    #398475

    Hi!

    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,
    Elliott

    #640953

    Not 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):

    #641257

    Hi,

    Your code looks fine to me, is it working?

    Thanks,
    Rikard

    #642174

    It looks like it is working :-). Thanks!

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Adding facebook code into head’ is closed to new replies.