2014-09-01 49 views
1

我正在使用prestashop 1.6。我想在頁眉頂部和頁腳底部添加谷歌廣告。我嘗試了很多方法,但都沒有成功。請如何在我的prestashop網站中添加腳本? 在此先感謝。如何在Prestashop - 1.6的頂部標題中添加廣告腳本?

+0

這可能是有用的:https://gist.github.com/hereswhatidid/8c8edef106ee95138b03「的PrestaShop媒體類覆蓋,以允許迫使一些內嵌的JavaScript保持在線。 「 – belford 2015-07-31 09:38:18

回答

0

正確的方法應該是使用一個模塊。同時檢查htmlpurifier函數是否阻止您的腳本標記。

0

有點晚了,但它是通過使用{literal} //script here {/literal}解決的。它應該只在腳本中有大括號的情況下使用,但它可以工作。

3

你應該找到header.tpl文件: https://github.com/PrestaShop/PrestaShop/blob/develop/themes/default-bootstrap/header.tpl

<head> 
    {$HOOK_HEADER} 
    <link rel="stylesheet" href="http{if Tools::usingSecureMode()}s{/if}://fonts.googleapis.com/css?family=Open+Sans:300,600&amp;subset=latin,latin-ext" type="text/css" media="all" /> 
    <!--AdWords Code--> 
</head> 

記住要禁用JS CCC選項(尤其是移動JS爲末): enter image description here

{literal}{/literal}標籤的任何內容都不解釋,但顯示爲原樣

{literal} 
<script type="text/javascript"> 
// ... 
</script> 
{/literal} 

{ldelim}{rdelim}用於逃避模板分隔符,默認情況下{}

<script type="text/javascript"> 
function foo() {ldelim} 
    // ... 
{rdelim} 
</script> 

給出:

<script type="text/javascript"> 
function foo() { 
    // ... 
} 
</script> 

如果仍然有問題,你可以嘗試重寫媒體類別:

https://gist.github.com/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> 

忽略原始

<?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; 
    } 
} 
相關問題