Hello, I would like to know to important thing for my website that is base on Enfold Theme
1- How can I replace the helper-main-menu.php file on my child theme I already made a directory “includes” and put the file in the without results.
2- How can I add a class to Header when scroll down via JS I try to write this code on functions.php in my child theme without results I need it to work in mobile and tablets as well, and without the sticky header for Desktop. we want the sticky header just for mobile.
function add_custom_script(){
?>
<script>
(function($){
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 50) {
$(“#header”).addClass(“header-scrolled”);
} else {
$(“#header”).removeClass(“header-scrolled”);
}
})(jQuery);
</script>
<?php
}
add_action(‘wp_footer’, ‘add_custom_script’);
My website is beachtourshawaii.com :)
Thanks you so much.
Hey beachtourshawaii,
Sorry for the late reply, I tested adding a “helper-main-menu.php” to the child theme by creating a directory “includes” in the child theme and then adding the “helper-main-menu.php” and this does work.
\wp-content\themes\enfold-child\includes\helper-main-menu.php
Please try again, or perhaps explain your changes in the file so we can test.
I corrected your function above, Try adding this code to the end of your child theme functions.php file in Appearance > Editor:
function custom_class_script(){
?>
<script>
(function($){
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 50) {
$("#header").addClass("header-scrolled");
} else {
$("#header").removeClass("header-scrolled");
}
});
})(jQuery);
</script>
<?php
}
add_action('wp_footer', 'custom_class_script');
please clear your browser cache and check.
Best regards,
Mike