我收到以下错误:
Uncaught TypeError: $ is not a function
只有当我没有登录我的WP帐户时。
我已经按照建议将var $
更改为jQuery
,但仍然得到相同的错误。
更新:
对不起,我没有提供任何代码。那么这是我想要正常工作的代码。但它不适用于任何插件的任何jquery。
我在我的wordpress主题中加入了Jquery,画廊工作到现在为止。
<script>
jQuery(document).ready(function($) {
$('.woocommerce-MyAccount-navigation-link--customer-logout').html('<a href="https://thepuzzleclub.com.au/puzzle-club-fundraising/">Member Details</a>');
$('.woocommerce-MyAccount-navigation').children().append('<li class="woocommerce-MyAccount-navigation-link woocommerce-MyAccount-navigation-link--customer-logout"><a href="https://thepuzzleclub.com.au/my-account/customer-logout/">Logout</a></li>');
$('#affwp-affiliate-dashboard-tabs').prepend('<li class="affwp-affiliate-dashboard-tab"><a href="https://thepuzzleclub.com.au/my-account/">Account Details</a></li>');
$('#header').append('<a class="icon-member-top" href="https://thepuzzleclub.com.au/my-account/"><i class="fa fa-sign-in" aria-hidden="true"></i><span class="text-log-in">MEMBER AREA</span></a>');
$('#header').append('<a class="icon-join-top" href="https://thepuzzleclub.com.au/become-a-partner/"><i class="fa fa-truck" aria-hidden="true"></i><span class="text-log-in">JOIN THE PUZZLE CLUB</span></a>');
$(window).scroll(function() {
var scroll = $(window).scrollTop();
//>=, not <=
if (scroll >= 60) {
//clearHeader, not clearheader - caps H
$("#headerwrap").addClass("fixed-header");
$("#body").addClass("spacing-top");
$("#header").addClass("header-on-scroll");
}
else{
$("#headerwrap").removeClass("fixed-header");
$("#body").removeClass("spacing-top");
$("#header").removeClass("header-on-scroll");
}
});
});
</script>
有什么建议吗?
我假设您在functions.php中加载脚本
// add it like this
///includes/resources/js is the path to your script
wp_enqueue_script( 'my-script', get_template_directory_uri() . '/includes/resources/js/my-script.js', array( 'jquery' ) );