2013-05-09 95 views
0

我目前正致力於將名爲Rekreato的HTML5模板轉換爲wordpress主題。我設法設置了一個簡單的主題,但是每當我使用jQuery腳本激活任何插件時,我的一些jQuery效果就被打破了。具體來說,我在Firefox調試器中獲得 -激活wordpress插件打破jQuery效果

TypeError: jQuery.easing[jQuery.easing.def] is not a function @ jquery.easing.1.3.js:46

這是page in question。你可以看到一半左右的圖像滑塊不起作用。我留下了一個活動的插件,名爲WP eMember。

我已經嘗試了許多事情,像配置我的主題作爲一個兒童主題,包裝jquery.easing.1.3在文檔就緒函數,並在代碼中移動腳本調用,但無濟於事。我甚至不確定緩動腳本是否有問題。答案可能在我面前凝視着我,但我似乎無法弄清楚。提前謝謝了。

編輯:優秀的建議從markratledge。我用wp_register_script()和wp_enqueue_script()將這些腳本放在functions.php中。起初我很困惑,更多的事情被打破了。進一步閱讀,我看到,由於Wordpress在其內置的jQuery庫中使用noConflict包裝,$快捷方式不可用。所以,我瀏覽了所有在檢查器中顯示錯誤的腳本,並用'jQuery'替換了'$'。瞧!一切都很好。再次感謝!

回答

1

檢查出Function Reference/wp enqueue script « WordPress Codex關於如何在WordPress主題中加載JS並避免出現jQuery錯誤,並顯示示例。

您正在通過直接鏈接加載一堆jQuery,但隨後出現wp_head併爲插件加載更多jQuery,併發生衝突。即,兩個不同的主要jQuery庫;檢查Firefox控制檯以獲取所有正在加載的JS的列表。

從這個DOC:

wp_enqueue_script links a script file to the generated page at the right time according to the script dependencies, if the script has not been already included and if all the dependencies have been registered. You could either link a script with a handle previously registered using the wp_register_script() function, or provide this function with all the parameters necessary to link a script.

This is the recommended method of linking JavaScript to a WordPress generated page.