• Resolved Matthieu-P. Schapranow

    (@theschappy)


    Dear Fancybox for WP team,

    Error message in browser console: undefined is not a function (near ‘…jQuery(“a.fancyboxforwp”).fancyboxforwp…’)
    Plugin Vers.: 1.3.4
    How to reproduce: Enable the plugin setting “Load JavaScript in Footer”
    Quick fix: Do not load code in footer until fixed.

    Description:
    The error is thrown by js code generated in line 418 in fancybox.php.

    Reason: The plugin uses correctly the wp_register_script and wp_enqueue_script function to enqueue the main js in mfbfw_enqueue_scripts on line 185.

    In addition, mfbfw_init is added as action for the hook wp_footer at line 471.

    However, you cannot ensure that enqueue_script is executed before mfbfw_init at this stage. In my case, the custom js code generated by mfbfw_init is placed before the enqueue command is executed. Thus, the required dependencies are not loaded properly.

    Possible fix: Please wrap your handcrafted js code (in particular but not limited to) line 418 in a wp_add_inline_script call for javascript fancybox-for-wp. Thus, the custom code will be place inline while the loading dependency will be ensured by WordPress code. Furthermore, it would be a good idea to check for existence of the required function in javascript or to add try / catch clause just in case.

    Thank you for your great work!

    Matthieu

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘fancyboxforwp is not a function when code loaded in footer’ is closed to new replies.