WP:如何删除wp_enqueue_script中的版本号?

Sta*_*bie 5 wordpress wordpress-theming

我正在尝试删除版本号,使其显示在生成的URL中wp_enqueue_script.看来我应该nullhttp://codex.wordpress.org/Function_Reference/wp_enqueue_script上传递第4个参数:

wp_enqueue_script('jquery', false, array(), null, false);
Run Code Online (Sandbox Code Playgroud)

它不起作用.我仍然看到版本号.我该如何删除?

另外,我如何使用wp_enqueue_script以便从Google CDN获取jQuery?

Rob*_*Lee 10

你可以使用

wp_enqueue_script('jquery', 'URL', array(), '', false);
Run Code Online (Sandbox Code Playgroud)

要么

wp_enqueue_script('jquery', 'URL', array(), null, false);
Run Code Online (Sandbox Code Playgroud)

或者你可以放一个通用名称占位符

wp_enqueue_script('jquery', 'URL', array(), 'custom', false);
Run Code Online (Sandbox Code Playgroud)

但特别是对于"jquery",如果要替换它,我会取消注册默认值

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');
Run Code Online (Sandbox Code Playgroud)

  • 这对我有用:`wp_register_script('jquery', $GoogleJqueryURI, array(), null, false);`。它需要 URL 不包含查询字符串。输入“custom”会产生这样的结果:`?ver=custom`,这不是我想要的。 (2认同)