2012-07-05 49 views
0

我剛換我的jQuery排隊的方式在一個主題從此方法:爲什麼jQuery不使用wordpress入隊?

function my_init() { 
if (!is_admin()) { 
    // comment out the next two lines to load the local copy of jQuery 
    wp_deregister_script('jquery'); 
    wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', false, '1.7.2'); 
    wp_enqueue_script('jquery'); 
} 
} 
add_action('wp_enqueue_scripts', 'my_init'); 

這樣:

function my_scripts_method() { 
wp_enqueue_script('jquery'); 
} 
add_action('wp_enqueue_scripts', 'my_scripts_method'); 

function my_admin_scripts_method() { 
wp_enqueue_script('jquery'); 
} 
add_action('admin_enqueue_scripts', 'my_admin_scripts_method'); 

舊版本使用1.7.2,WordPress的內置版本爲1.7。 1。我試圖將1.7.1的地址複製並粘貼到第一個版本中,並且它的打破情況也是如此。鏈接在1.7.1版本的源代碼中存在,但jquery不起作用。任何想法可能會導致這種情況?

網址:www.brainbuzzmedia.com/themes/vertex/

回答

0

我不知道究竟是什麼問題在這裏,但試試這個。

function wptuts_scripts_with_jquery() 
{ 
    // Register the script like this for a plugin: 
    wp_register_script('custom-script', plugins_url('/js/custom-script.js', __FILE__), array('jquery')); 
    // or 
    // Register the script like this for a theme: 
    wp_register_script('custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery')); 

    // For either a plugin or a theme, you can then enqueue the script: 
    wp_enqueue_script('custom-script'); 
} 
add_action('wp_enqueue_scripts', 'wptuts_scripts_with_jquery'); 

更多info ...

0
function my_scripts_method() { 
if (!is_admin()) { 
    wp_enqueue_script('jquery'); 
} 
} 
add_action('wp_enqueue_scripts', 'my_scripts_method'); 

function my_admin_scripts_method() { 
// you don't need to load jquery here, because its automatically loaded in the adminby default 
} 
add_action('admin_enqueue_scripts', 'my_admin_scripts_method');