Archived topic
jQuery only works when I'm logged in
7 replies · Started by Antonio on July 11, 2019
Hi,
I am using GP premium to add Hooks to a website. In the specific I have small script in the wp_head and usually I use the same on other projects and it always works.
I realised that the script is loaded only when I am logged in WordPress.
I try to deactivate all the plugins (security and cache plugins etc.) but is not solving the problem.
This is the script:
<script>
jQuery(document).ready(function($){
$(document.body).on("mouseenter mouseleave", ".kg-1", function() {
$('.w_01').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-2", function() {
$('.w_02').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-3", function() {
$('.w_03').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-4", function() {
$('.w_04').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-5", function() {
$('.w_05').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-6", function() {
$('.w_06').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-7", function() {
$('.w_07').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-8", function() {
$('.w_08').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-9", function() {
$('.w_09').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-10", function() {
$('.w_10').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-11", function() {
$('.w_11').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-12", function() {
$('.w_12').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-13", function() {
$('.w_13').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-14", function() {
$('.w_14').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-15", function() {
$('.w_15').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-16", function() {
$('.w_16').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-17", function() {
$('.w_17').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-18", function() {
$('.w_18').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-19", function() {
$('.w_19').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-20", function() {
$('.w_20').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-21", function() {
$('.w_21').toggle();
});
$(document.body).on("mouseenter mouseleave", ".kg-22", function() {
$('.w_22').toggle();
});
});
</script>
Thats the error I get when I am not logged in:
Uncaught ReferenceError: jQuery is not defined at (index):61
Do you have any tips?
Thanks in advance!!!
Hi there,
try moving your script to the WP_footer hook as your site currently calls jQuery in the footer.
Hi David,
Unfortunately is not working.
I already tried and this is the error I get:
Uncaught ReferenceError: jQuery is not defined at (index):2038
I really can't explain why.
Issue: jQuery is being called near to the very bottom of the wp_footer so the script needs to come after that. You can do this by increasing the Hook Priority - try 25 or higher.
Hi David,
Wow that's great. Now is working properly.
Thanks a lot for you support.
You guys are awesome!
You're welcome.
I was facing the same problem. Thank you Antonio for asking this question and thank you David for the rescue :)
Glad we could be of help :)