News:

Wondering if this will always be free?  See why free is better.

Main Menu

Help Please - Placing code under <head>

Started by JF3000, August 30, 2016, 12:40:27 AM

Previous topic - Next topic

JF3000

I need to place some code under the <head> and in between the <body> on the default theme. Which template file do I do this into please?

I would like to place it onto the index page please.

Thank you.

Sir Osis of Liver

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

JF3000

Looking at the code looks like I have to place in between the echo ' is this right?

JF3000

Trying to place this under the head

<script data-cfasync='false' type='text/javascript'>/*<![CDATA[*/(function (a, c, s, u){'Insticator'in a || (a.Insticator={ad:{loadAd: function (b){Insticator.ad.q.push(b)}, q: []}, helper:{}, embed:{}, version: "2.0", q: [], load: function (t, o){Insticator.q.push({t: t, o: o})}}); var b=c.createElement(s); b.src=u + new Date(Math.floor(new Date().getTime() / 6e5) * 6e5).getTime(); b.async=!0; var d=c.getElementsByTagName(s)[0]; d.parentNode.insertBefore(b, d)})(window, document, 'script', '//www.insticator.com/embeds/script?sid=c2f62050-5606-4019-867b-7f317c6f4c16&cbt=');/*]]>*/</script>

and this under the body

<div id="insticator-container"><div id="div-insticator-ad-1"></div><div id="insticator-embed"></div><div id="div-insticator-ad-2"></div><script data-cfasync='false' type="text/javascript">/*<![CDATA[*/Insticator.ad.loadAd("div-insticator-ad-1");Insticator.ad.loadAd("div-insticator-ad-2");Insticator.load("em",{id : "00982e36-3039-4e6c-9529-e48146b78e86"})/*]]>*/</script></div>

Any tips please, cant seem to get it to work with the echo tag is there an optional tag to use for this?

Thanks

Wellwisher

You need to escape all single quotes in your code aka: ' and you do this by adding backslash next to it so it looks like this: \'

JF3000

How am I to know where to place the / next to the '. I did try and got an error.

// insticator head
echo '<script data-cfasync='false' type='text/javascript/'>/*<![CDATA[*/(function (a, c, s, u){/'Insticator/'in a || (a.Insticator={ad:{loadAd: function (b){Insticator.ad.q.push(b)}, q: []}, helper:{}, embed:{}, version: "2.0", q: [], load: function (t, o){Insticator.q.push({t: t, o: o})}}); var b=c.createElement(s); b.src=u + new Date(Math.floor(new Date().getTime() / 6e5) * 6e5).getTime(); b.async=!0; var d=c.getElementsByTagName(s)[0]; d.parentNode.insertBefore(b, d)})(window, document, /'script/', '/www.insticator.com/embeds/script?sid=c2f62050-5606-4019-867b-7f317c6f4c16&cbt=/');/*]]>*/</script>';

//insticator body
echo '<div id="insticator-container"><div id="div-insticator-ad-1"></div><div id="insticator-embed"></div><div id="div-insticator-ad-2"></div><script data-cfasync=/'false/' type="text/javascript">/*<![CDATA[*/Insticator.ad.loadAd("div-insticator-ad-1");Insticator.ad.loadAd("div-insticator-ad-2");Insticator.load("em",{id : "00982e36-3039-4e6c-9529-e48146b78e86"})/*]]>*/</script></div>';

Kindred

you need to escape **EVERY** single quote within the echo statement...

Also "I got an error" is an absolutely useless statement.
When you are reporting issues, indicate the SPECIFIC error that you got...

Also, when saying "I added the code"
include the lines just before and after what you added...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Sir Osis of Liver

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Wellwisher

If you're struggling a little bit, there are quite a few SMF add-ons which allow you to add ad-units or javascript to your header and footer sections. All this without having to make any changes to your own code or tinker with SMF core files. Have a look at this mod which basically does what you're asking:

http://custom.simplemachines.org/mods/?mod=351

JF3000

#9
Tried the mod and even though I placed the code it didn't place the final effect. There were no errors just didn't show anything.

JF3000

Head:
echo \'<script data-cfasync=\'false\' type=\'text/javascript\'>/*<![CDATA[*/(function (a, c, s, u){\'Insticator\'in a || (a.Insticator={ad:{loadAd: function (b){Insticator.ad.q.push(b)}, q: []}, helper:{}, embed:{}, version: "2.0", q: [], load: function (t, o){Insticator.q.push({t: t, o: o})}}); var b=c.createElement(s); b.src=u + new Date(Math.floor(new Date().getTime() / 6e5) * 6e5).getTime(); b.async=!0; var d=c.getElementsByTagName(s)[0]; d.parentNode.insertBefore(b, d)})(window, document, \'script\', \'//www.insticator.com/embeds/script?sid=c2f62050-5606-4019-867b-7f317c6f4c16&cbt=\');/*]]>*/</script>\';

Body:
echo \'<div id="insticator-container"><div id="div-insticator-ad-1"></div><div id="insticator-embed"></div><div id="div-insticator-ad-2"></div><script data-cfasync=\'false\' type="text/javascript">/*<![CDATA[*/Insticator.ad.loadAd("div-insticator-ad-1");Insticator.ad.loadAd("div-insticator-ad-2");Insticator.load("em",{id : "00982e36-3039-4e6c-9529-e48146b78e86"})/*]]>*/</script></div>\';


There was a problem loading the /Themes/default/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\).

Where did I go wrong here please?

Kindred

you escaped the opening and closing quotes for the echo...  as stated - you need to escape the single quotes WITHIN the echo...

e.g. echo '....    not echo \'....
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Matthew K.

In the time you've taken to tell the original poster how they aren't doing it right, and trying to explain it to them, when they obviously don't understand code, you could've fixed it for them five times over and had a happy customer.
Quote from: Kindred on August 31, 2016, 11:05:42 AM
you escaped the opening and closing quotes for the echo...  as stated - you need to escape the single quotes WITHIN the echo...

e.g. echo '....    not echo \'....

Kindred

except not.... since
1- I am posting and frequently post form a mobile device, so writing and correcting extended lines of code is difficult and time consuming
2- teaching how to do it himself is more useful, in the long run than just handing him the code...

Also, finally...  he's only ever included HIS line of code, instead of what I origiunally asked, which was include several lines of code before and after the place he wants to add his code... because there is a good chance that he may be putting his code within another echo statement.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

JF3000

You already know what the other code is its the index template file. I don't want the answer or someone to just give it to me, I need to learn and I am doing so with the comments, thank you.

Illori

Quote from: JF3000 on August 31, 2016, 12:16:13 PM
You already know what the other code is its the index template file.

no we dont know what code is in the index.template.php file as it can vary per theme and change if mods have been installed. we do ask for information for a reason. if a solution is to be found the answers sould be provided.

JF3000

I now have it working, thank you for everyones help.

Advertisement: