Wordpress覆盖Jquery问题

Wordpress覆盖Jquery问题,jquery,jquery-plugins,wordpress,wordpress-theming,Jquery,Jquery Plugins,Wordpress,Wordpress Theming,基本上这就是我正在做的: 当我在functions.php上执行此操作时,它不起作用 //functions.php add_action('init', 'override_jquery'); function override_jquery() { if( !is_admin()){ wp_deregister_script('jquery'); wp_enqueue_script( 'nashgraphics_jquery_library', ge

基本上这就是我正在做的:

当我在functions.php上执行此操作时,它不起作用

//functions.php
add_action('init', 'override_jquery');

function override_jquery() {
    if( !is_admin()){
        wp_deregister_script('jquery');
        wp_enqueue_script( 'nashgraphics_jquery_library', get_template_directory_uri() . '/bootstrap/js/jquery-1.9.0.min.js');
    }
}
当我把它作为一个插件使用时,它就可以工作了

//my_plugin.php
add_action('wp_enqueue_scripts', 'override_jquery');

function override_jquery() {
    $plugin_location=WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
    if( !is_admin()){
        wp_deregister_script('jquery');
        wp_enqueue_script( 'nashgraphics_jquery_library', $plugin_location . 'fancybox/library/jquery-1.9.0.min.js');
    }
}
我的问题是我需要通过functions.php重写JQuery库,因为我正在尝试开发我自己的主题,它需要不同版本的JQuery

不要将jquery库作为插件覆盖,因为如果禁用插件,这将是一个严重的问题


有人能解释一下,当我在functions.php中使用jquery库时,它为什么不包括它,而当我将它作为插件使用时,它却可以工作?

您没有再次命名
jquery
脚本。试试这个:

function override_jquery() {
    if( !is_admin()){
        wp_deregister_script('jquery');
        wp_register_script( 'jquery', get_template_directory_uri() . '/bootstrap/js/jquery-1.9.0.min.js');
        wp_enqueue_script('jquery');
    }
}

您应该注意,不建议在WordPress中使用您自己的jQuery。阅读并阅读。

是否使用子主题?不,我正在尝试创建父主题