This is an interesting one because I don’t specifically enqueue jQuery. This is what I do
// Frontend Scripts.
wp_register_script(
‘bod-modal-block-js’, // Handle.
plugins_url( ‘/dist/modal.js’, dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
array( ‘jquery’ ), // Dependencies, defined above.
filemtime( plugin_dir_path( __DIR__ ) . ‘dist/blocks.build.js’ ), // Version: File modification time.
true // Enqueue the script in the footer.
);
So I enqueue my js script in the footer which is the recommended approach. I also have a dependency for jQuery, which basically says hey this code uses jQuery if its not already been loaded then load it. At least that is what it should do but this is down to WordPress I don’t really have a say. I will try and do some digging.
Thanks @merbmerb for following up, appreciate it. Really liking your plugin, was hoping that it was one of the other plugins on my site that caused the menu to break..
Hi @merbmerb. Just wondering if you’d had a chance to look into this or if you could say something about the likelyhood of an update?
All the best, Th
Hi thanks for the reminder. OK so I did a test using a different theme, actually the twenty twenty one theme which also uses jQuery. I looked at the code and jQuery is in the header even when I am using the modal plugin. This basically means that my specifying jQuery as a prerequisite is not changing the position of where its included, it is something specific with the theme you are using.
Having said that if you want to keep the theme and the modal plugin you can try removing my prerequisite. Remove array(‘jquery’) from the below code which is located in wp-content/plugins/modal-block/src/init.php . If you do make this change and it works you would need do this change for each new version of the modal plugin.
// Frontend Scripts.
wp_register_script(
‘bod-modal-block-js’, // Handle.
plugins_url( ‘/dist/modal.js’, dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
array( ‘jquery’ ), // Dependencies, defined above.
filemtime( plugin_dir_path( __DIR__ ) . ‘dist/blocks.build.js’ ), // Version: File modification time.
true // Enqueue the script in the footer.
);
Actually just had another idea, try looking at this https://ww.wp.xz.cn/support/topic/v2-1-update-exposes-some-js-issues-in-theme/
It could be the way the theme is invoking jQuery. If you let me know your site I can check.
Thanks @merbmerb for following up.
I’m rather illieterate when it comes to PHP so the thread you linked to doesn’t tell me much. Also, manually modifing plugin code would in my case be an invitation to breaking things, every time, and not remember to fix it 🙂
Looking for a way to send you a direct message for the URL, there is no option for that here, is there?