简体   繁体   English

将外部脚本移至Wordpress页脚

[英]Moving external scripts to wordpress footer

I have some external scripts in my "wordpess head" like this:- 我的“ wordpess头像”中有一些外部脚本,例如:

//blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js //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 https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.0/masonry.pkgd.min.js

I want to move these scripts to my wordpress Footer. 我想将这些脚本移至我的Wordpress页脚。 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. 如果使用wp_enqueue_script函数加载脚本, wp_enqueue_script可以提供参数(入队函数中的最后一个参数),该参数告诉WP将脚本直接入队到网站的页脚。 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)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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