wp_enqueue JavaScript in child-theme (ReferenceError)

  • Unknown's avatar

    This is my first post here, so I hope I pasted the code well and you’ll stand by interpreting the problem.

    I have deregistered and dequeued two scripts in my childtheme. When removing and adding only the first script (listing.js) all works fine, no problem. But when I also remove and add the second script (modules.js) the page becomes dysfunctional and certain (also other) scripts can’t be found / aren’t defined anymore.

    Here‘s a screenshot of what my debug plugin gives me.

    Here‘s the relevant part of my functions.php in childtheme:

    function remove_script() {
          wp_deregister_script( 'search_and_go_elated_listings' );
          wp_dequeue_script(  'search_and_go_elated_listings' );
    
          wp_deregister_script( 'search_and_go_elated_modules' );
          wp_dequeue_script(  'search_and_go_elated_modules' );
    
        }
        add_action( 'wp_print_scripts', 'remove_script', 20 );
    
        function add_script() {
        	wp_enqueue_script( 'bijles_search_and_go_elated_listings',  get_stylesheet_directory_uri() . '/assets/js/listings.js', array('jquery', 'underscore', 'jquery-ui-autocomplete'), false, true );
        	wp_enqueue_script( 'bijles_search_and_go_elated_modules', get_stylesheet_directory_uri() . '/assets/js/modules.js', array('jquery'), false, true  );
        };
        add_action( 'wp_enqueue_scripts', 'add_script', 30);

    My best guess is that the problem is related to the dependencies of wp_enqueue.

    Similar but unanswered question can be found [here][2]:

    Hope you all can help me out. I’ve been learning but can’t figure this out myself!

  • Hi there, and welcome!

    These forums are for sites hosted on WordPress.com, but you’re running the WordPress software on your own hosting.

    You can try getting help with your child theme by posting your question in the WordPress.org forum for your theme. If you’re using a free theme available over at WordPress.org, it will have its own forum linked off the main theme page.

    You’ll need a free WordPress.org account to post – if you don’t already have one, you can register here:

    https://wordpress.org/support/register.php

    If you’re using a premium theme, you should contact the theme developer through its support channels.

  • The topic ‘wp_enqueue JavaScript in child-theme (ReferenceError)’ is closed to new replies.