Wordpress上的所有已加载文件' function.php以Wordpress版本号结束

时间:2017-08-08 04:12:24

标签: php wordpress twitter-bootstrap

我使用以下代码从functions.php向WordPress加载bootstrap和其他相关文件:

function enqueue_script(){
    wp_enqueue_script('jquery','//code.jquery.com/jquery-3.2.1.min.js');
    wp_enqueue_script('bootstrap.min.js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js');
}

add_action( 'wp_enqueue_scripts', 'enqueue_script');

它正确加载但在渲染的html文件上,引导程序文件以Wordpress的版本号结尾。例如:

<link rel='stylesheet' id='bootstrap.min.css-css'  href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css?ver=4.8.1' type='text/css' media='all' />

我该如何纠正?

3 个答案:

答案 0 :(得分:1)

试试这个

wp_register_script('jquery-load', '//code.jquery.com/jquery-3.2.1.min.js', array(), '3.2.1');
wp_enqueue_script('jquery-load');

wp_register_script('bootstrap.min', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array(), '3.3.7'); //
wp_enqueue_script('bootstrap.min'); // Enqueue it!

注意wp_register_script

中的4个参数

答案 1 :(得分:1)

要从CSS / js中删除版本,请将以下代码添加到您的有效主题function.php文件中。

// Remove WP Version From Styles    
add_filter( 'style_loader_src', 'sdt_remove_ver_css_js', 9999 );
// Remove WP Version From Scripts
add_filter( 'script_loader_src', 'sdt_remove_ver_css_js', 9999 );

// Function to remove version numbers
function sdt_remove_ver_css_js( $src ) {
    if ( strpos( $src, 'ver=' ) )
        $src = remove_query_arg( 'ver', $src );
    return $src;
}

你也可以去插件(点击谷歌,你会很容易找到)。其中一个给出如下: -

CS Remove Version Number From CSS & JS

注意: - 还检查一些其他代码选项: -

WP: how to remove version number in wp_enqueue_script?

答案 2 :(得分:0)

您可以使用以下代码并参考此处wp enqueue scripts

function enqueue_script(){
    wp_enqueue_script('jquery','//code.jquery.com/jquery-3.2.1.min.js', array(), '3.2.1');
    wp_enqueue_script('jquery');

    wp_enqueue_script('bootstrap.min.js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array(), '3.3.7');
    wp_enqueue_script('bootstrap.min');
}

请尝试一下,让我知道。     add_action(&#39; wp_enqueue_scripts&#39;,&#39; enqueue_script&#39;);