In theme development, what is the best way to register and enqueue JavaScript files to avoid problems with plugins?
I want to create a theme which uses scripts like jQuery, Masonry and so on. I downloaded the scripts and added them via the reqister and enqueue function to avoid problems with Wordpress Updates.
function my_scripts() {
// Register scripts
wp_register_script( 'my_masonry', get_template_directory_uri() . '/js/masonry.pkgd.min.js', array(), '1.0.0', true );
// Add scripts before closing body tag.
wp_enqueue_script( 'my_masonry', true );
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
The other way would be to use the built-in Wordpress scripts to may avoid problems with plug-ins.
function my_scripts() {
// Add scripts before closing body tag.
wp_enqueue_script( 'masonry', true );
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
What is the better approach?