在WordPress中:链接到标题中的JS有效,在函数中行到JS.php不要


in wordpress: link to js inside header works, line to js in functions.php don't

我有这个奇怪的问题。

我的头中有一个指向 js 文件的链接.php我想将它们移动到函数.php。问题是当我这样做时,我在控制台中收到此错误。 (有些东西不起作用)

Uncaught TypeError: Object [object Object] has no method 'sharrre'

所以我现在在标题中使用这个链接.php现在。

<script src="http://sharrre.com/js/jquery.sharrre-1.3.4.min.js"></script>

我使用此代码将其移动到函数中.php

// load the theme JS
function theme_scripts() {
    wp_enqueue_script( 'sharrre', 'http://sharrre.com/js/jquery.sharrre-1.3.4.min.js' );
}
add_action( 'wp_enqueue_scripts', 'theme_scripts' );

问题可能是什么?

您可以尝试一些方法来使其正常工作。

  1. 绝对确保您的脚本被拉入页面,一种检查方法是使用 Chrome 调试器中的"来源"选项卡并搜索文件。

  2. 确保在包含
  3. 脚本后已包含脚本jQuery,因为它肯定依赖于此。

  4. 将函数名称重命名为更独特的名称。可能是导致与另一个呼叫发生冲突。尝试命名 sharrre_jquery_script()