2011-04-25 91 views

回答

0

Jquery已經與Wordpress安裝打包在一起,並且可以使用它。 安裝新的Wordpress博客時請檢查源代碼。

8

雖然答案之一已被接受,但我覺得下面的技術可能會幫助某人。

Plugin Pagefunction.php

function include_jQuery() { 
    if (!is_admin()) { 
     wp_enqueue_script('jquery'); 
    } 
} 
add_action('init', 'include_jQuery'); 

包含以下代碼當然你可以使用任何有意義的功能名稱,而不是關閉include_jQuery

或者,你可以使用下面的代碼:

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

最後,作爲一般規則,你不應該使用$變量jQuery,除非你已經使用了shortcuts之一。以下是如何快捷jQuery來安全地使用$變量的例子:

jQuery(function ($) { 
    /* You can safely use $ in this code block to reference jQuery */ 
}); 

你可能喜歡從那裏我個人學習上述技術(S)THIS鏈接爲好。非常感謝Ericm Martin!