I am using prestashop 1.6 . I want to add google ads in top of the header and bottom in footer. I tried many ways but all are not succeed. Please how can i add script in my prestashop website? Thanks in advance.
I am using prestashop 1.6 . I want to add google ads in top of the header and bottom in footer. I tried many ways but all are not succeed. Please how can i add script in my prestashop website? Thanks in advance.
Share Improve this question asked Sep 1, 2014 at 10:32 Bhavesh PatelBhavesh Patel 1251 gold badge2 silver badges14 bronze badges 1- It may be useful : gist.github./hereswhatidid/8c8edef106ee95138b03 "PrestaShop Media class override to allow for forcing some inline JavaScripts to remain inline." – Pawel Gumiela Commented Jul 31, 2015 at 9:38
3 Answers
Reset to default 4You need to find header.tpl file: https://github./PrestaShop/PrestaShop/blob/develop/themes/default-bootstrap/header.tpl
<head>
{$HOOK_HEADER}
<link rel="stylesheet" href="http{if Tools::usingSecureMode()}s{/if}://fonts.googleapis./css?family=Open+Sans:300,600&subset=latin,latin-ext" type="text/css" media="all" />
<!--AdWords Code-->
</head>
Remember to disable CCC options for JS (especially moving JavaScript to the end):
Anything within {literal}{/literal}
tags is not interpreted, but displayed as-is
{literal}
<script type="text/javascript">
// ...
</script>
{/literal}
{ldelim}
and {rdelim}
are used for escaping template delimiters, by default {
and }
:
<script type="text/javascript">
function foo() {ldelim}
// ...
{rdelim}
</script>
gives:
<script type="text/javascript">
function foo() {
// ...
}
</script>
If you still have a problem you may try to override Media Class:
https://gist.github./hereswhatidid/8c8edef106ee95138b03
<p>Some HTML goes here</p>
<script type="text/javascript" data-keepinline="true">
// this script will remain here when rendered
alert( "hello!" );
</script>
<script type="text/javascript">
// this script will be forced to the bottom of the page
alert( "hello again!" );
</script>
Media.php:
<?php
Class Media extends MediaCore
{
public static function deferScript($matches)
{
if (!is_array($matches))
return false;
$inline = '';
if (isset($matches[0]))
$original = trim($matches[0]);
if (isset($matches[1]))
$inline = trim($matches[1]);
/* This is an inline script, add its content to inline scripts stack then remove it from content */
if (!empty($inline) && preg_match('/<\s*script(?!.*data-keepinline)[^>]*>/ims', $original) !== 0 && Media::$inline_script[] = $inline)
return '';
/* This is an external script, if it already belongs to js_files then remove it from content */
preg_match('/src\s*=\s*["\']?([^"\']*)[^>]/ims', $original, $results);
if (isset($results[1]) && (in_array($results[1], Context::getContext()->controller->js_files)
|| in_array($results[1], Media::$inline_script_src)))
return '';
/* return original string because no match was found */
return $original;
}
}
The correct way should be using a module. Also check if the function htmlpurifier is blocking your scripts tags.
A little late, but it is solved by using {literal} //script here {/literal}
. It's supposed to be used only if there are curly brackets in your script, but it works.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744173888a4561662.html
评论列表(0条)