0

I am trying to load a custom js script in my storefront child theme. But the script doesn't load anymore (after upgrading a few plugins).

My js script is in /wp-content/themes/HemenTheme. I have this in my functions.php:

function my_scripts_method() {
    wp_enqueue_script(
        'custom-script',
        get_stylesheet_directory_uri() . '/custom_menu_script.js',
        array( 'jquery' )
    );
    echo get_stylesheet_directory_uri() . '/custom_menu_script.js';
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

the echo gives :

<mydomaine>/wp-content/themes/HemenTheme/custom_menu_script.js

but the js code in the script is not run.

here's the begining of the js script:

console.log("on est dans le script avant doc ready");


jQuery( document ).ready( function() {

console.log("on est dans le script");

    /*toggle du sous menu DESKTOP ET MOBILE*/
    var masthead       = jQuery( '#masthead' );
    var siteNavigation = masthead.find( '.main-navigation > div > ul' );
    siteNavigation.find( 'a' ).off( 'focus.storefront blur.storefront touchstart.storefront resize.storefront');
...

EDIT: I tried this https://wordpress.stackexchange.com/a/255217/121787. But it doesn't work.

  • Is your custom_menu_script.js in the same directory as the child theme stylesheet, or is it in a separate directory? Is this happening on the live site or are you working in a development environment? Have you looked in Developer Tools for any potential errors? – Bagseye Oct 5 '18 at 10:12
  • Yes it is on the same directory. It was working perfectly before. We're working on a live test environment. No errors in the console. – Louis Oct 5 '18 at 12:27
  • Have you looked in the network tab of the Developer Tools? What is the status of your file? – parameciostudio Oct 5 '18 at 13:16
  • Do you see your custom_menu_script.js when you view source the page? It could be an issue with the handler name as well. "custom-script" seems a common handle and maybe the parent theme already had is enqueued. Try changing the handler name too. – Karun Oct 5 '18 at 16:13
  • I think you may need to post either a link to the live/dev site. If there is one. Or more infomration from Developer Tools such as from the Network tab - here you will be able to see if the stylesheet has loaded at all, or the Console tab - here you should have an error related to the reasons why it cannot load the file. At the moment, I feel there is not enough information to go on. – Bagseye Oct 8 '18 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.