Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1417594

    Steve C
    Participant

    Hi guys,

    I need to add the following code to a site on all pages. I tried the scripts n styles plug-in which had worked for me on another site, but it hasn’t taken for some reason.

    It needs to be in the Body element of every page.

    Do you have any suggestions, would be greatly appreciated!

    <!-- Quantcast Tag -->
    <script type="text/javascript">
    var _qevents = _qevents || [];
    
    (function() {
    var elem = document.createElement('script');
    elem.src = (document.location.protocol == "https:" ? "https://secure" : "http://edge") + ".quantserve.com/quant.js";
    elem.async = true;
    elem.type = "text/javascript";
    var scpt = document.getElementsByTagName('script')[0];
    scpt.parentNode.insertBefore(elem, scpt);
    })();
    
    _qevents.push({
    qacct:"p-Jw6cuZBU3Y0qw"
    });
    </script>
    
    <noscript>
    <div style="display:none;">
    <img src="//pixel.quantserve.com/pixel/p-Jw6cuZBU3Y0qw.gif" border="0" height="1" width="1" alt="Quantcast"/>
    </div>
    </noscript>
    <!-- End Quantcast tag -->
    #1417606

    Steve C
    Participant
    This reply has been marked as private.
    #1417811

    Christian
    Moderator

    Hey Steve,

    X has an action hook below the opening <body> tag (x_before_site_begin) so you could tap into it to add your script like

    add_action( 'x_before_site_begin', 'my_script' );
    
    function my_script() { ?>
    <!-- Quantcast Tag -->
    <script type="text/javascript">
    var _qevents = _qevents || [];
    
    (function() {
    var elem = document.createElement('script');
    elem.src = (document.location.protocol == "https:" ? "https://secure" : "http://edge") + ".quantserve.com/quant.js";
    elem.async = true;
    elem.type = "text/javascript";
    var scpt = document.getElementsByTagName('script')[0];
    scpt.parentNode.insertBefore(elem, scpt);
    })();
    
    _qevents.push({
    qacct:"p-Jw6cuZBU3Y0qw"
    });
    </script>
    
    <noscript>
    <div style="display:none;">
    <img src="//pixel.quantserve.com/pixel/p-Jw6cuZBU3Y0qw.gif" border="0" height="1" width="1" alt="Quantcast"/>
    </div>
    </noscript>
    <!-- End Quantcast tag -->
    <?php }

    The code should be added in your functions.php. Please notice the PHP tags because depending on your setup, you might need to close the PHP tag or else, you’ll get a fatal error.

    Thanks.

    #1422874

    Steve C
    Participant

    Implemented without blowing up the site, so far so good!

    I’ll let you know if it’s all working ok, but looks like it will all be good…

    Many thanks chaps!

    #1423214

    Prasant Rai
    Moderator

    You are most welcome. 🙂