Enqueue scripts to footer

时间:2015-12-18 作者:tom84

我知道如何将带有wp\\u dequeue\\u script和wp\\u enqueue\\u script的单个脚本打印到页脚:

function dequeue_my_scripts() {
 wp_dequeue_script(\'dgx_donate_paypalstd_script\');
}
add_action( \'wp_print_scripts\', \'dequeue_my_scripts\', 11 );

function enqueue_scripts_to_footer() {
   wp_enqueue_script(\'dgx_donate_paypalstd_script\');
}
add_action( \'wp_footer\', \'enqueue_scripts_to_footer\' );
但是我怎样才能在页脚上打印几个脚本呢。是否可以使用枚举,例如:

function dequeue_my_scripts() {
 wp_dequeue_script(\'dgx_donate_paypalstd_script\',\'next-handle-script\',        \'next-handle-script\'.....);
}
add_action( \'wp_print_scripts\', \'dequeue_my_scripts\', 11 );

function enqueue_scripts_to_footer() {
   wp_enqueue_script(\'dgx_donate_paypalstd_script\',\'next-handle-script\',     \'next-handle-script\'.....);
}
add_action( \'wp_footer\', \'enqueue_scripts_to_footer\' );
还是有其他可能性??

2 个回复
最合适的回答,由SO网友:Omar Tariq 整理而成

像这样:-

function dequeue_my_scripts() {
   wp_dequeue_script(\'dgx_donate_paypalstd_script\');
   wp_dequeue_script(\'next-handle-script\');
   wp_dequeue_script(\'next-handle-script-2\');
   /* and so on*/
}
add_action( \'wp_print_scripts\', \'dequeue_my_scripts\', 11 );

function enqueue_scripts_to_footer() {
   wp_enqueue_script(\'dgx_donate_paypalstd_script\');
   wp_enqueue_script(\'next-handle-script\');
   wp_enqueue_script(\'next-handle-script-2\');
   /* and so on */
}
add_action( \'wp_footer\', \'enqueue_scripts_to_footer\' );
此实现中有什么问题?

EDIT:

我还想通知您,这是您正在努力实现的目标的正确实现:-

function enqueue_scripts_to_footer() {
   wp_enqueue_script(\'dgx_donate_paypalstd_script\', false, array(), false, true);
   wp_enqueue_script(\'next-handle-script\', false, array(), false, true);
   wp_enqueue_script(\'next-handle-script-2\', false, array(), false, true);
   /* and so on */
}
add_action( \'wp_enqueue_scripts\', \'enqueue_scripts_to_footer\' );

SO网友:C C

抄本之外:wp\\u enqueue\\u script函数调用的第五个参数是一个布尔值,用于告诉它是否将脚本放入页脚:

https://codex.wordpress.org/Function_Reference/wp_enqueue_script

相关推荐