首先,我知道还有很多其他的“jQuery未定义”线程,我已经把它们全部检查了一遍,似乎找不到解决方案。试图将jQuery功能添加到定制的主题导航中,我似乎无法回避这个问题。代码在JSFIDLE中运行良好https://jsfiddle.net/TonyTheOnly/h7xwcb8h/
但当我尝试在wordpress主题中执行此操作时,我得到了一个错误“jQuery未定义”
收割台
</head>
<body <?php body_class( $awesome_classes ); ?>>
<div class="topBar">
<img src="<?php header_image();?>" height="120px;" width="100px;" alt=""/ class="siteLogo">
<div class="topBarMiddle">
<p>español | ENGLISH</p>
</div>
<div class="topBarRight">
<nav>
<a class="burger-nav"></a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</div>
</div>
功能
<?php
function paramo_script_enqueue() {
wp_enqueue_style(\'customstyle\', get_template_directory_uri() . \'/css/paramo.css\', array(), \'1.0.0\', \'all\');
wp_enqueue_script(\'customjs\', get_template_directory_uri() . \'/js/paramo.js\', array(\'jQuery\'), \'1.0.0\', true);
}
add_action(\'wp_enqueue_scripts\', \'paramo_script_enqueue\');
function paramo_theme_setup() {
add_theme_support(\'menus\');
register_nav_menu(\'primary\', \'Primary Header Navigation\');
register_nav_menu(\'secondary\', \'Footer Navigation\');
}
add_action(\'init\', \'paramo_theme_setup\');
add_theme_support(\'custom-header\');
jQuery
/*global $, jQuery, alert*/
jQuery(function () {
"use strict";
$(".burger-nav").on("click", function () {
$("nav ul").toggleClass("open");
});
});
非常感谢您的帮助,感谢您抽出时间!