在这个文件中
wp-include/script-loader.php
有以下代码:
$scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '1.11.3');
$scripts->add( 'jquery-core', '/wp-includes/js/jquery/jquery.js', array(), '1.11.3');
$scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '1.2.1');如何将jquery放在脚注中?
我尝试过添加第五个参数"true“或"1",但不起作用。
...
* Localizes some of them.
* args order: $scripts->add( 'handle', 'url', 'dependencies', 'query-string', 1 );
* when last arg === 1 queues the script for the footer
...我想把jquery放在底部,因为它阻塞了正确的页面加载(google页面速度推荐)。
发布于 2016-02-27 03:00:22
您必须先排掉它的队列,然后再对它进行排队。下面的代码将完全满足您的需要。
function jquery_mumbo_jumbo()
{
wp_dequeue_script('jquery');
wp_dequeue_script('jquery-core');
wp_dequeue_script('jquery-migrate');
wp_enqueue_script('jquery', false, array(), false, true);
wp_enqueue_script('jquery-core', false, array(), false, true);
wp_enqueue_script('jquery-migrate', false, array(), false, true);
}
add_action('wp_enqueue_scripts', 'jquery_mumbo_jumbo');发布于 2018-02-15 11:46:06
在经历了所有这些问题之后,在没有joy的情况下,测试解决了我自己的问题,我决定一次性迁移所有的脚本。
那么,如何更好地编写一些代码,将所有的脚本文件,现在和未来加载到页脚中。防止这种疼痛重演。对于您可能添加的任何插件,也很方便。
打开你的functions.php文件并添加这个坏男孩
// Script to move all Head scripts to the Footer
function remove_head_scripts() {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
}
add_action( 'wp_enqueue_scripts', 'remove_head_scripts' );
// END of ball ache发布于 2016-02-27 00:13:53
Cf文档:scripts
你有一个钩子: wp_enqueue_scripts
使用:
function themeslug_enqueue_script() {
wp_enqueue_script( 'my-js', 'filename.js', false );
}
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_script' );https://stackoverflow.com/questions/35663927
复制相似问题