【问题标题】:insert javascript into wordpress将javascript插入wordpress
【发布时间】:2014-01-17 06:10:20
【问题描述】:

我目前正在使用我已将内联插入到 wordpress 帖子中的 javascript 函数 -- 这是代码:

<script type="text/javascript">// <![CDATA[
document.getElementById('FBsharer').onclick = function () {
  var url = 'https://www.facebook.com/sharer/sharer.php?u=';
  url += encodeURIComponent(location.href);
  window.open(url, 'fbshare', 'width=640,height=320');
};
// ]]></script>

代码在插入到我的帖子中时可以正常工作--

但是当我尝试从位于我的 wp_includes 文件夹中的外部文件中调用 javascript 时,它不再起作用。

我知道我从 WP_includes 调用的 JS 文件有效——因为我在该文件中有其他脚本可以正常工作。

我对 JS 很陌生——所以我确信我只是格式化了一些错误的东西——或者遗漏了一些简单的东西。

有人知道如何将这个 JS 文件从其当前位置(在我的帖子中内联)移动到我从 wp_includes 文件夹调用的 JS 文件中吗?

非常感谢!

【问题讨论】:

  • 永远不要更新 wp_includ 文件夹中的任何内容。最好在你的主题文件夹中添加你的js并将它包含在你的头文件中。

标签: javascript wordpress


【解决方案1】:

您只需在 wp-content/thems 文件夹中创建一个文件或文件夹,并在您的 theam 中通过 header.php 文件链接后保存您的脚本文件。永远不要更改 wp-include 文件夹和内容。

普通链接

<script type="text/javascript" src="/scripts/emailpage.js"></script>

Wordpress 链接

<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/pathto/yourscript.js"></script>

更多参考follow this link

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多