i will start at the beginning.

I have a website that is running the Master Slider Pro wordpress plugin and the iLightBox plugin. I am running a custom script in a custom.js file in wordpress child theme.

From what i understand, the custom.js file requires the ilightbox file to be loaded which in turn requires jQuery to be loaded.

My current code looks like the below:

/* Ensure jquery loads before iLightBox */
add_action( 'wp_enqueue_scripts', 'add_my_script' );

            function add_my_script() {
                wp_register_script( 'ilightbox_script', get_theme_root_uri() . '/Avada/includes/class-avada-scripts.php', array('jquery'), true );
                wp_register_script( 'custom-script', get_stylesheet_directory_uri() . '/assets/js/custom.js', array('jquery', 'ilightbox_script'), true );

At present i get the following error:

Uncaught TypeError: jQuery(...).iLightBox is not a function

To narrate, what i believe i am doing is:

  1. register my themes script that includes the iLightBox function, this will register once jQuery has been loaded.
  2. register my custom.js file which will register once jQuery and iLightBox has been loaded.
  3. Load the ilightbox script.
  4. Load the custom.js script.

My page can be seen below: http://www.complete-models.com/gallery/cars-trucks/124-dodge-monaco/

Am i going wrong here ?

  • You actually don't need wp_enqueue_script('ilightbox_script');. The system will load dependencies automatically. This looks like a Javascript problem-- that is, it looks like iLightBox isn't defined. Are you sure that is the correct function name?
    – s_ha_dum
    Nov 22, 2015 at 23:19
  • I am certain iLightBox is a function. I can get the whole thing working with the following code, however it i visit another page then hit back the error appears. It looks to me like sometimes jQuery loads before the custom.js and the ilightbox script (correctly) and other times loads after it (incorrectly) which throws the error. function custom_scripts() { wp_register_script( 'custom-script', get_stylesheet_directory_uri() . '/assets/js/custom.js', array('jquery') , false, true ); wp_enqueue_script( 'custom-script' ); } add_action( 'wp_enqueue_scripts', 'custom_scripts', 99 ); Nov 23, 2015 at 7:45
  • @s_ha_dum any ideas Nov 23, 2015 at 21:27
  • I expect that the problem is in your JavaScript. Does the script wait for the page to load?
    – s_ha_dum
    Nov 23, 2015 at 22:48

1 Answer 1


Issue resolved. nothing wrong with the script i posted. turns out i was calling the wrong file in the first wp_register_script()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.