WordPress wp_register_script函数没有在页脚中加载脚本

Mr *_*r B 2 php wordpress jquery footer wordpress-plugin

我试图在正文完成之前在我的博客页脚中加载托管在谷歌上的JQuery.这是我在functions.php文件中使用的函数.

function load_jquery() {
if (!is_admin()) {
    wp_deregister_script('jquery');
    // load the Google API copy in the footer
    wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js', array(), '1.5.1', 1);
    wp_enqueue_script('jquery');
}
}
add_action('init', 'load_jquery');
Run Code Online (Sandbox Code Playgroud)

但是它会继续加载到标题中.我无法弄清楚为什么.

我还在functions.php文件中添加了以下函数,它工作正常;

function your_function() {
    echo '<p>This is inserted at the bottom</p>';
}
add_action('wp_footer', 'your_function');
Run Code Online (Sandbox Code Playgroud)

感谢帮助.

小智 5

我怀疑依赖于jquery的其他脚本之一未设置为在页脚中加载.由于脚本依赖于jquery,因此jquery将被加载到头部.