As I understand there are Worpress core files:
imagesloaded.min.js
masonry.min.js
jquery.masonry.min.js
which are are loaded by WordPress core.
Can we manually add them into our JavaScript files and disable showing them using functions.php?
As I understand there are Worpress core files:
imagesloaded.min.js
masonry.min.js
jquery.masonry.min.js
which are are loaded by WordPress core.
Can we manually add them into our JavaScript files and disable showing them using functions.php?
You could load them into your own JS files, but I would probably recommend not doing that. I am guessing you are wanting to optimize and load just one JS file? I don’t think it would be a good idea. Let the browser parallel load and such.
If you want to still disable them, you should be able to using something like…
add_action( 'wp_print_scripts', 'dequeue_masonry', 100 );
function dequeue_masonry() {
wp_dequeue_script( 'masonry' );
wp_dequeue_script( 'jquery-masonry' );
}
So give that a try.
Edit: The trick here is the wp_dequeue_script part.
Yes, you technically can deregister them and include your own version, but I’d be careful with that.
WordPress loads those files in a specific way and some themes or plugins depend on the core-registered handles. In a few projects I worked on, replacing them manually caused layout issues later when a plugin expected the core version.
A safer approach is to use wp_dequeue_script() and wp_deregister_script(), then re-register your version with wp_register_script(), keeping the same handle and proper dependencies. That way WordPress still manages the load order correctly.
In general, I only replace core scripts when there’s a clear reason (like performance or version conflicts), otherwise leaving the core versions avoids unexpected problems.
Yes, technically you can copy those files into your own JS and deregister them from functions.php — but it’s not a good idea in most cases.
WordPress already manages these scripts properly.
Other plugins/themes may depend on them.
If you remove them, something else might break.
You’ll lose automatic updates from WordPress core.
Just load them as dependencies in your custom script:
function my_theme_scripts() {
wp_enqueue_script(
'my-script',
get_template_directory_uri() . '/js/custom.js',
array('jquery', 'imagesloaded', 'masonry'),
'1.0',
true
);
}
add_action('wp_enqueue_scripts', 'my_theme_scripts');
That’s it. WordPress will handle everything safely.
If WordPress already provides the script → use it, don’t replace it.
Only deregister them if you’re 100% sure nothing else is using them.
Your suggestion is good.