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 418infancybox.php.Reason: The plugin uses correctly the
wp_register_scriptandwp_enqueue_scriptfunction to enqueue the main js inmfbfw_enqueue_scriptson line 185.In addition,
mfbfw_initis added as action for the hookwp_footerat line 471.However, you cannot ensure that
enqueue_scriptis executed beforemfbfw_initat this stage. In my case, the custom js code generated bymfbfw_initis 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_scriptcall 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.