gpt4 book ai didi

javascript - 如何在 Prestashop - 1.6 的顶部标题中添加广告脚本?

转载 作者:行者123 更新时间:2023-11-30 10:12:41 25 4
gpt4 key购买 nike

我正在使用 prestashop 1.6 。我想在页眉顶部和页脚底部添加谷歌广告。我尝试了很多方法,但都没有成功。请问如何在我的 prestashop 网站中添加脚本?提前致谢。

最佳答案

你需要找到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 选项(尤其是将 JavaScript 移到末尾): 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:

<?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;
}
}

关于javascript - 如何在 Prestashop - 1.6 的顶部标题中添加广告脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25603817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com