wp_unregister和wp_enqueue
有人建议我用wp_unregister和wp_enqueue用google托管的一个替换wordpress jquery库(因为wordpress有一些问题)
但是,当我尝试将这些插入我的wordpress网站时,它会破坏我的网站。
我需要以某种方式包装它们吗?
wp_unregister_script('jquery'); wp_unregister_script('jquery-ui-core'); wp_enqueue_script('jquery', https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js); wp_enqueue_script('jquery-ui-core', https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js);
我的网站有一个自定义文件夹,我可以放置自定义function。 我没试成功
function googlejqueryhost(){ } add_action('wp_head', 'googlejqueryhost');
根据我在这篇博文中演示的代码,如何:
function load_jquery() { // only use this method is we're not in wp-admin if (!is_admin()) { // deregister the original version of jQuery wp_deregister_script('jquery'); // discover the correct protocol to use $protocol='http:'; if($_SERVER['HTTPS']=='on') { $protocol='https:'; } // register the Google CDN version wp_register_script('jquery', $protocol.'//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2'); // add it back into the queue wp_enqueue_script('jquery'); } } add_action('template_redirect', 'load_jquery'
我使用模板重定向钩子,我想知道这是什么导致你的问题。
无论哪种方式,如果这不起作用,你可以提供有关该问题的更多信息,你有一个链接到该网站?
编辑
哦,你的函数也打开了PHP标签,真的应该已经打开了,看看我的评论……
function googlejqueryhost(){ // AND HERE, remove this }
编辑2
您会注意到您的网站现在正在从Google的CDN正确加载jQuery,另一个脚本与jQuery库本身无关。