fancyboxforwp is not a function when code loaded in footer
-
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 inline 418
infancybox.php
.Reason: The plugin uses correctly the
wp_register_script
andwp_enqueue_script
function to enqueue the main js inmfbfw_enqueue_scripts
on line 185.In addition,
mfbfw_init
is added as action for the hookwp_footer
at line 471.However, you cannot ensure that
enqueue_script
is executed beforemfbfw_init
at this stage. In my case, the custom js code generated bymfbfw_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 javascriptfancybox-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
- The topic ‘fancyboxforwp is not a function when code loaded in footer’ is closed to new replies.