简体   繁体   中英

Moving external scripts to wordpress footer

I have some external scripts in my "wordpess head" like this:-

//blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js
or https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.0/masonry.pkgd.min.js

I want to move these scripts to my wordpress Footer. I know that these can be done via

function dequeue_my_scripts()  and function enqueue_scripts_to_footer() 

to use these functions i need a Script Handle. Has anybody an idea how i can move these external scripts?

If you load your scripts with wp_enqueue_script function, you can provide parameter (the last parameter in enqueue function), which tells WP to enqueue script directly to the footer of the site. Something like this:

add_action( 'wp_enqueue_scripts', 'my_scripts' );
function my_scripts() {
   //this script will be included in the WP foother because of the last `true` parameter
   wp_enqueue_script('masonry', 'https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.0/masonry.pkgd.min.js', [], '3.3.0', true)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM