• Resolved mleder

    (@mleder)


    I’m attempting to add an analytics script to the <head> section of a site (all pages). I have tried using a few plugins which will add the script. I also have attempted the add using a content builder (they have an “add to head” form section).

    No matter what tool I use, upon submit to write the script, the site comes back with a 404. (The content builder just hangs with an hourglass. All other saving activities are normal – meaning I can upload media, save edits, create pages, etc.).

    – Using Nginx. Error log in Nginx shows no errors.
    – I made sure that all files and folders are set with proper permissions.
    – Debugging in wp-config is set to on/true.
    – Using a child theme.

    Any ideas? Thanks for your help!
    Mark

    • This topic was modified 9 years, 1 month ago by mleder.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Can you post the script you are trying to add?

    • This reply was modified 9 years, 1 month ago by luckychingi.
    Thread Starter mleder

    (@mleder)

    <!– Hotjar Tracking Code for https://www.universaldesigntoolkit.com –>
    <script>
    (function(h,o,t,j,a,r){
    h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
    h._hjSettings={hjid:487615,hjsv:5};
    a=o.getElementsByTagName(‘head’)[0];
    r=o.createElement(‘script’);r.async=1;
    r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
    a.appendChild(r);
    })(window,document,’//static.hotjar.com/c/hotjar-‘,’.js?sv=’);
    </script>

    • This reply was modified 9 years, 1 month ago by mleder. Reason: Didn't surround with code
    Thread Starter mleder

    (@mleder)

    <!-- Hotjar Tracking Code for https://www.universaldesigntoolkit.com -->
    <script>
        (function(h,o,t,j,a,r){
            h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
            h._hjSettings={hjid:487615,hjsv:5};
            a=o.getElementsByTagName('head')[0];
            r=o.createElement('script');r.async=1;
            r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
            a.appendChild(r);
        })(window,document,'//static.hotjar.com/c/hotjar-','.js?sv=');
    </script>

    can you see if https://www.smartlook.com/ works
    they offer the same service and more viewers a month
    try adding https://ww.wp.xz.cn/plugins/addfunc-head-footer-code/ plugin and add the head code in there

    Thread Starter mleder

    (@mleder)

    Still throws the 404 even with the plug in you recommend. I’ve tried with other scripts, same problem. So I don’t think its a script issue.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You need to be careful when adding that code into any plugin that handles insertion of JS because the code above is not just JS but HTML and JS. Some plugins won’t handle the HTML tags.

    Thread Starter mleder

    (@mleder)

    OK, so how would I enqueue this script properly and put it in functions.php so it’s called in the <head> area. That to me would be the ideal solution, but I haven’t found docs that CLEARLY give an explanation.

    BTW: I also tried reinstalling 4.74 and resetting permissions.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Try this plugin: https://ww.wp.xz.cn/plugins/custom-css-js/

    But add this JS instead of the above:

    
      (function(h,o,t,j,a,r){
            h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
            h._hjSettings={hjid:487615,hjsv:5};
            a=o.getElementsByTagName('head')[0];
            r=o.createElement('script');r.async=1;
            r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
            a.appendChild(r);
        })(window,document,'//static.hotjar.com/c/hotjar-','.js?sv=');
    
    Thread Starter mleder

    (@mleder)

    Nice Plugin! Works like a champ!
    Thanks for the tip.

    Mark

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Adding Script to Page Head throws 404’ is closed to new replies.