Hi all,
I'm hoping someone will be able to help me insert the Viglink script in the proper location in the index.template.php file. I've done some research and learned I need to add \ before every ' but still errors.
Here is the script I need to add:
<script type="text/javascript">
var vglnk = {key: 'b27c327a33221fbd44a77db81ff6b4d1'};
(function(d, t) {
var s = d.createElement(t);
s.type = 'text/javascript';
s.async = true;
s.src = '//cdn.viglink.com/api/vglnk.js';
var r = d.getElementsByTagName(t)[0];
r.parentNode.insertBefore(s, r);
}(document, 'script'));
</script>
And here is the section in the file where I think I am supposed to be inserting the script:
// Show the load time?
if ($context['show_load_time'])
echo '
<p>', $txt['page_created'], $context['load_time'], $txt['seconds_with'], $context['load_queries'], $txt['queries'], '</p>';
echo '
</div></div>', !empty($settings['forum_width']) ? '
</div>' : '';
}
function template_html_below()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo '
</body></html>';
}
// Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
function theme_linktree($force_show = false)
Any guidance would be greatly appreciated!
Thanks.
i'm not sure what all you have done already and that you can undo, there is a mod for that to make it easier ;)
https://custom.simplemachines.org/index.php?mod=2817
Try this and add it before the closing body tag.
Open index.template.php and find:
function template_html_below()
{
// Load in any javascipt that could be deferred to the end of the page
template_javascript(true);
echo '
Add your code after echo '
<script type="text/javascript">
var vglnk = {key: \'b27c327a33221fbd44a77db81ff6b4d1\'};
(function(d, t) {
var s = d.createElement(t);
s.type = \'text/javascript\';
s.async = true;
s.src = \'//cdn.viglink.com/api/vglnk.js\';
var r = d.getElementsByTagName(t)[0];
r.parentNode.insertBefore(s, r);
}(document, \'script\'));
</script>
This is for 2.0.x (I can tell from the markup in the OP) so template_javascript(true); does not exist, but the same general idea will work if the apostrophes are all escaped in the javascript.
This runs without syntax errors on a test site (although I have not actually tested it for VigLink functionality):
function template_html_below()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo '
<script type="text/javascript">
var vglnk = {key: \'b27c327a33221fbd44a77db81ff6b4d1\'};
(function(d, t) {
var s = d.createElement(t);
s.type = \'text/javascript\';
s.async = true;
s.src = \'//cdn.viglink.com/api/vglnk.js\';
var r = d.getElementsByTagName(t)[0];
r.parentNode.insertBefore(s, r);
}(document, \'script\'));
</script>
</body></html>';
}
I totally forgot about 2.0 :o ;D
Okay, thanks guys! I really appreciate the direction. I'll give it a try and let you know.
Yeah.. I'm still on older software I guess. To be honest, I may be the most uniformed and least technically inclined forum owner here! Lol. I really need to work on that. I only own this one site and only because it was a topic I was interested in and saw a need for a community.. so I stumbled my way through installing simple machines 7 years ago and have been pretty much hands off since.
Fast forward to today, and my site is getting 150k pageviews a month and growing pretty fast and might actually produce me a bit of side income. I download manual backups through cpanel but that is the extent of my abilities. I don't know how to check the backups or even re-upload them should I ever need to. I don't even want to try installing that mod bc if something happened, I wouldn't know how to fix it. I can however make a copy of the index.template.php file and replace it if there are errors. Foolish, I know.
Now I need to upgrade to the latest software release, install SSL certificate, and be able to manage backups more effectively since I have a community depending on me to keep the information they've worked so hard on alive. Any advice on where to start? I would be willing to pay someone to help me out and get me up to speed if need be.
Thanks again.
Okay so I installed the script as Antechinus described with no errors and the "check your installation" tool on Viglink said it detected the link and install was successful. Awesome. Thanks a lot.