1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.3 How to add cutom code to every page

Discussion in 'Styling and Customization Questions' started by duderuud, Jun 29, 2014.

  1. duderuud

    duderuud Active Member

    Hey guys,

    I want to find out how many of our users use adblockers. Pagefair should do that trick.
    For Tradefair to work you have to add some code to all pages, something like this:

    Code:
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
    <script type="text/javascript">
        (function() {
            function async_load(script_url){
                var protocol = ('https:' == document.location.protocol ? 'https://' : 'http://');
                var s = document.createElement('script'); s.src = protocol + script_url;
                var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
            }
            bm_website_code = 'xxxxxxxxxxxx';
            jQuery(document).ready(function(){async_load('asset.pagefair.com/measure.min.js')});
            jQuery(document).ready(function(){async_load('asset.pagefair.net/ads.min.js')});
        })();
    </script>
    Where can I add that code?
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Where can additional JavaScript be placed?
    Additional JavaScript can be placed in the PAGE_CONTAINER, page_container_js_head or page_container_js_body templates. If PAGE_CONTAINER is used, it can be placed anywhere in the template. If page_container_js_head is used, it will be included in the head section of PAGE_CONTAINER. If page_container_js_body is used, it will be included in the body section of PAGE_CONTAINER, after the footer. It depends on the JavaScript to a large extent; some require to be placed in the head, some in the body.

    http://xenforo.com/community/threads/frequently-asked-questions.5183/#post-181112
     
    octabrain and adwade like this.
  3. duderuud

    duderuud Active Member

    Sorry I didn't find that FAQ before. It worked, thanks!
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You shouldn't include jquery again as XenForo already includes the jQuery library.

    Code:
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
    <script type="text/javascript">
        (function() {
            function async_load(script_url){
                var protocol = ('https:' == document.location.protocol ? 'https://' : 'http://');
                var s = document.createElement('script'); s.src = protocol + script_url;
                var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
            }
            bm_website_code = 'xxxxxxxxxxxx';
            jQuery(document).ready(function(){async_load('asset.pagefair.com/measure.min.js')});
            jQuery(document).ready(function(){async_load('asset.pagefair.net/ads.min.js')});
        })();
    </script>
     
  5. duderuud

    duderuud Active Member

    Thanks for the info Jake, the Google jquery is removed.
     

Share This Page