$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>urls - How to remove file versions from the file source links in wp_head?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

urls - How to remove file versions from the file source links in wp_head?

matteradmin8PV0评论

I observed the inside the wp_head function in the source links of every .css, .js files a ?ver=1 (or other number based on the file's/library version) is added. How can I overwrite them, to remove them?

This issue I think is causing problems on the cache manifest part.

I observed the inside the wp_head function in the source links of every .css, .js files a ?ver=1 (or other number based on the file's/library version) is added. How can I overwrite them, to remove them?

This issue I think is causing problems on the cache manifest part.

Share Improve this question edited Feb 9, 2019 at 0:01 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Apr 18, 2013 at 15:07 user17408user17408
Add a comment  | 

2 Answers 2

Reset to default 15

You can hook into style_loader_src and script_loader_src and run remove_query_arg( 'ver', $url ) on the URL:

<?php
/* Plugin Name: Remove version parameter for scripts and styles */

add_filter( 'style_loader_src', 't5_remove_version' );
add_filter( 'script_loader_src', 't5_remove_version' );

function t5_remove_version( $url )
{
    return remove_query_arg( 'ver', $url );
}

Without this plugin:

After plugin activation:

There is one case where that will fail: When someone didn’t use the script/style API, but added a hard coded string to the header.

This worked for me when I still had to load a stylesheet from Google Fonts.

<?php
add_filter( 'script_loader_src', 'wpse130419_remove_script_version', 15, 1 );
add_filter( 'style_loader_src',  'wpse130419_remove_script_version', 15, 1 );
function wpse130419_remove_script_version( $src ) {

    $url = explode( '?', $src );

    if ( $url[0] === 'http://fonts.googleapis/css' ) :
        $version = explode( '&ver=', $url[1] );
        $url[1]  = $version[0];
    endif;

    return ( $url[0] === 'http://fonts.googleapis/css' ) 
        ? "{$url[0]}?{$url[1]}"
        : $url[0]
    ;
}
Post a comment

comment list (0)

  1. No comments so far