【发布时间】:2021-12-01 18:25:57
【问题描述】:
我正在尝试将 jquery 集成到我的 wordpress 主题中。我已将此代码集成到我的 function.php 中,但它不起作用。任何人都可以看到问题吗?谢谢。
//Enqueue Child Styles & Scripts on the Front-End
add_action('wp_enqueue_scripts', function(){
wp_enqueue_style('nebula-child'); //Stylesheets
wp_enqueue_script('nebula-main'); //Scripts
wp_enqueue_script( 'custom', get_stylesheet_directory_uri() . '/assets/js/custom.js', array ( 'jquery', '3.3.2'), '', true);
}, 327);
我的 custom.js 文件:
jQuery(document).ready(function($){
console.log( "ready!" );
});
【问题讨论】:
-
你可以点击开发者工具的网络标签,检查是否加载了custom.js
-
很遗憾没有加载
-
您的 custom.js 文件是否有任何 404 错误未找到?您确定文件在此路径中的位置正确吗?此外,您能否给我们一个指向您的域 - 站点的链接?
-
我在控制台中没有与此问题相关的错误,也没有 404 错误。正如霍华德所说,不在我的 wp_enqueue_ 脚本中指定“jquery”就足够了