I created a small custom script that fixes a sidebar at different point depending on if there is a banner. I used enqueue script in my child functions file and then a custom.js file with my javascript. See below:
function.php (In Child Theme Folder)
function custom_scripts() {
wp_register_script( 'custom-script', get_stylesheet_directory_uri() . '/custom.js', array() , false, true );
wp_enqueue_script( 'custom-script' );
}
add_action( 'wp_enqueue_scripts', 'custom_scripts', 99 );
custom.js (In Child Theme Folder)
$(function() {
var div = $(".sidebar-wrapper");
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if ($(".sidebar-wrapper").closest(".mk-main-wrapper").length && scroll > 147) {
div.addClass("fixed-product-nav");
} else if (scroll > 263) {
div.addClass("fixed-product-nav");
} else {
div.removeClass("fixed-product-nav");
}
});
});
Like I said, this worked perfectly, but now my WP theme (Jupiter), has done an update that now uses require.js and they have told me WordPress enqueue script will no longer work. Is that true or do I just need to use a different way to load the script?
Since this is custom work, the theme support will not help.
When I look at the page source code, I can see that the custom.js is loaded on the page so that made me think something was wrong with the script, but it used to work perfectly and the HTML structure of the page has not changed.
So I guess the real question is how do I get my custom.js to load and work like it did, but with require.js?
The site is in development mode so I'm sorry but I cannot share a public link.
Any help is greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire