Hi @presse2009,
Change the file name from ‘function.php’ to ‘functions.php’.
Thanks
@vishakha07 Thank you. But it does not work π
Hi @presse2009,
Replace code with the given one
function twentySven_register_scripts() {
wp_enqueue_script( 'twentySven-js', get_template_directory_uri() . '/assets/js/script.js', array('jquery'), '1.0.0', true);
}
add_action( 'wp_enqueue_scripts', 'twentySven_register_scripts' );
and if you are using child theme the use ‘get_stylesheet_directory_uri()’ instead of ‘get_template_directory_uri()’.
Thanks
Hi @vishakha07 Thank you. I changed it. Hmmm, it does not work either. You are refering to a jquery dependency which I do not understand. (Maybe the keyword “Bootstrao” was misleading.) It’s just the Bootsrap css. The script is vanilla js βΒ in fact is this:
window.addEventListener("DOMContentLoaded", () => {
let scrollPos = 0;
const mainNav = document.getElementById("mainNav");
const headerHeight = mainNav.clientHeight;
window.addEventListener("scroll", function () {
const currentTop = document.body.getBoundingClientRect().top * -1;
if (currentTop < scrollPos) {
// Scrolling Up
if (currentTop > 0 && mainNav.classList.contains("is-fixed")) {
mainNav.classList.add("is-visible");
} else {
console.log(123);
mainNav.classList.remove("is-visible", "is-fixed");
}
} else {
// Scrolling Down
mainNav.classList.remove(["is-visible"]);
if (
currentTop > headerHeight &&
!mainNav.classList.contains("is-fixed")
) {
mainNav.classList.add("is-fixed");
}
}
scrollPos = currentTop;
});
});
So I would think I can skip the dependency part. I am sorry, eating your time. Cheers and thank you again.
Yeah, no jQuery there. We’re kind of guessing at the problem because it’s unclear where the problem lies.
Does the file reference appear in your page’s source HTML?
If so, does the link correctly lead to the file? When you follow the link, do you see your JS code?
If that checks out, it’s probably not working due to a script error (not necessarily yours, any error can prevent others from working). Check your browser’s console for errors.