Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Adding Code to HEAD and BODY tags?

Adding Code to HEAD and BODY tags?

Views: 9,254

Results 1 to 14 of 14
28 Jan 2010, 3:41 AM
#1
redpanda avatar

redpanda

New Zenner

Join Date:
Aug 2009
Posts:
59
Plugin Contributions:
0

Adding Code to HEAD and BODY tags?

Hi All,
I have a feedback module i would like to install but i am not very good with Zencart and when it asks me to add some code to the <head> and the <body> tags i don't know where i should put it.

Thanks,
Asher

28 Jan 2010, 4:14 AM
#2
kim avatar

kim

Obaa-san

Join Date:
Jun 2003
Posts:
26,602
Plugin Contributions:
0

Re: Adding Code to HEAD and BODY tags?

What kind of code?

28 Jan 2010, 5:05 AM
#3
redpanda avatar

redpanda

New Zenner

Join Date:
Aug 2009
Posts:
59
Plugin Contributions:
0

Re: Adding Code to HEAD and BODY tags?

The header needs some javascript and the body some html/css

28 Jan 2010, 5:14 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Adding Code to HEAD and BODY tags?

Put the javascript inside an appropriately-named file in the prescribed folder, according to this FAQ article, and Zen Cart will automatically load the code for you. No need to touch template files.
http://www.zen-cart.com/wiki/index.php/Customisation_-_Templates_-_Javascript

28 Jan 2010, 3:10 PM
#5
redpanda avatar

redpanda

New Zenner

Join Date:
Aug 2009
Posts:
59
Plugin Contributions:
0

Re: Adding Code to HEAD and BODY tags?

what about the body?

2 Feb 2010, 7:51 AM
#6
redpanda avatar

redpanda

New Zenner

Join Date:
Aug 2009
Posts:
59
Plugin Contributions:
0

Re: Adding Code to HEAD and BODY tags?

anyone know?

2 Feb 2010, 2:22 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Adding Code to HEAD and BODY tags?

What page are you wanting to put it on?
What's the code you're supposed to put in the body?

21 Apr 2011, 11:50 PM
#8
kehrli avatar

kehrli

Zen Follower

Join Date:
Aug 2007
Location:
Cannon Beach, OR
Posts:
180
Plugin Contributions:
0

Re: Adding Code to HEAD and BODY tags?

I need to put the following code into the <head> section of the home page:

<script type="text/javascript">
__compete_code = 'dcafd398df98a9f097d0384b52d77295';
(function () {
    var s = document.createElement('script'),
        e = document.getElementsByTagName('script')[0];
    s.src = (document.location.protocol.toLowerCase() === 'https:' ? 'https:' : 'http:') +
        '//c.compete.com/bootstrap/dcafd398df98a9f097d0384b52d77295/bootstrap.js';
    s.type = 'text/javascript';
    s.async = true;
    if (e) { e.parentNode.insertBefore(s, e); }
}());
</script>

This was a request from a company I'm using to do Google Analytics work for me. I didn't know how to convert this into a .js file. If someone can convert this to a form that can be used in a .js file, I can take care of it. But if not, is there a way to add this to the <head> section of the home page?

Thanks.

21 Apr 2011, 11:59 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Adding Code to HEAD and BODY tags?

One quick way to do it would be to dump all that code into a new file and upload it to your site as: /includes/modules/pages/index/jscript_compete-com.php

If it truly needs to only appear on the home page, put these two lines in the file first, and then add your code between these two lines:```

<?php if ($this_is_home_page) {?>

put your code here

<?php } ?>
22 Apr 2011, 12:38 AM
#10
kehrli avatar

kehrli

Zen Follower

Join Date:
Aug 2007
Location:
Cannon Beach, OR
Posts:
180
Plugin Contributions:
0

Re: Adding Code to HEAD and BODY tags?

Thanks, Dr Byte. I don't think it will hurt to have that code be available on other pages as well, but I don't know how to convert my code so that it can reside in a *.js file. I can't just copy it as is, can I? Or is it OK just as it is? I think I would at least take out the <script> tags, right?

Sorry, I'm not too savvy with java script.

22 Apr 2011, 1:30 AM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Adding Code to HEAD and BODY tags?

If you put it as-is in a PHP file as I indicated, it will work fine. No need to use a .js file.

22 Apr 2011, 1:47 AM
#12
kehrli avatar

kehrli

Zen Follower

Join Date:
Aug 2007
Location:
Cannon Beach, OR
Posts:
180
Plugin Contributions:
0

Re: Adding Code to HEAD and BODY tags?

Thanks a lot DrByte. That worked fine. In retrospect, I see I could have just tried it, and then seen the results with a "view source". I would have seen that it worked just fine. Sorry for the extra query. I didn't grasp what you were telling me to do at first.

22 Apr 2011, 3:50 AM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Adding Code to HEAD and BODY tags?

No worries. If you peek at the wiki link I posted earlier in this thread you'll see more about how this works.

3 Nov 2021, 11:02 AM
#14
flappingfish avatar

flappingfish

Zen Follower

Join Date:
Nov 2020
Posts:
312
Plugin Contributions:
2

Re: Adding Code to HEAD and BODY tags?

Hey guys, seems new forum posts are often missed, i created a new post after reading this post and trying to make an on load js file. it sort of worked so im close, was hoping someone could assst me in working out where i went wrong, im just trying to add trust pilot to my sites header to try and boost sales, if anyone can spare a bit of time to help be eternally grateful :)

https://www.zen-cart.com/showthread.php?228443-noob-trying-out-an-onload-js-help-please&highlight=trustpilot