WP: how to remove version number in wp_enqueue_script?

岁酱吖の 提交于 2019-12-18 08:31:49

问题


I'm trying to remove the version number from appearing in the URL generated by wp_enqueue_script. It seems like I should pass a null on the 4th parameter per http://codex.wordpress.org/Function_Reference/wp_enqueue_script:

wp_enqueue_script('jquery', false, array(), null, false);

It's not working. I still see the version number. How do I remove that?

Also, how do I use wp_enqueue_script so that I get jQuery from the Google CDN?


回答1:


You can either use

wp_enqueue_script('jquery', 'URL', array(), '', false);

or

wp_enqueue_script('jquery', 'URL', array(), null, false);

or you can put a generic name placeholder

wp_enqueue_script('jquery', 'URL', array(), 'custom', false);

But particularly with "jquery" I would deregister the default if you want to replace it

wp_deregister_script('jquery');
$GoogleJqueryURI = 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js';
wp_register_script('jquery', $GoogleJqueryURI, array(), 'custom', false);
wp_enqueue_script('jquery');



回答2:


try something like this:

wp_deregister_script('jquery'); 
wp_register_script('jquery', ('http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'), false, NULL);
wp_enqueue_script('jquery');

The $ver and $in_footer are optional. So just leave them off.

Also, if you use the google cdn then it will be hard to hide the version any way, its in the url.



来源:https://stackoverflow.com/questions/15062105/wp-how-to-remove-version-number-in-wp-enqueue-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!