我正在尝试修改页脚中排队脚本的插件,因为我的jQuery链接在页脚中。
插件:
add_action(\'wp_enqueue_scripts\', \'fjgwpp_addCSSandJS\');
function fjgwpp_addCSSandJS() {
//Register scripts
wp_register_script(
\'justifiedGallery\',
plugins_url(\'js/jquery.justifiedGallery.min.js\', __FILE__)
);
wp_register_script(
\'flickrJustifiedGalleryWPPlugin\',
plugins_url(\'js/flickrJustifiedGalleryWPPlugin.js\', __FILE__)
);
wp_register_script(
\'colorbox\',
plugins_url(\'lightboxes/colorbox/jquery.colorbox-min.js\', __FILE__)
);
if (fjgwpp_getOption(\'provideSwipebox\')) {
wp_register_script(
\'swipebox\',
plugins_url(\'lightboxes/swipebox/js/jquery.swipebox.min.js\', __FILE__)
);
}
//Enqueue scripts
wp_enqueue_script(\'jquery\');
wp_enqueue_script(\'justifiedGallery\');
wp_enqueue_script(\'flickrJustifiedGalleryWPPlugin\');
if (fjgwpp_getOption(\'provideColorbox\')) {wp_enqueue_script(\'colorbox\');
}
if (fjgwpp_getOption(\'provideSwipebox\')) {
wp_enqueue_script(\'swipebox\');
}
}
我试着设置
$in_footer = true
对于所有人
wp_register_script
和
wp_enqueue_script
像这样:
wp_enqueue_script(\'justifiedGallery\', true);
但脚本仍在
<head>
.
UPDATE
我改变了
wp_register_script
适用于:
wp_register_script(\'flickrJustifiedGalleryWPPlugin\', plugins_url(\'js/flickrJustifiedGalleryWPPlugin.js\', __FILE__), \'\', \'\', true);
现在脚本加载到页脚。但出现错误:未捕获引用错误:未定义jQueryFJGWPP
SO网友:Jen
从…起http://codex.wordpress.org/Function_Reference/wp_register_script:
<?php wp_register_script( $handle, $src, $deps, $ver, $in_footer ); ?>
这意味着您需要添加
$deps
和
$ver
值到
wp_register_script()
为了设置
$in_footer
. 像这样:
wp_register_script(
\'justifiedGallery\',
plugins_url(\'js/jquery.justifiedGallery.min.js\', __FILE__),
false, // or array(), or array(\'jquery\') if this depends on jQuery
\'1.0\', // or your plugin version, or the version of the js file
true // $in_footer
);