I
I
Itvanya2015-12-23 08:46:19
PHP
Itvanya, 2015-12-23 08:46:19

Wordpress: how to remove /?ver=... from file path?

Friends, there is a problem. The site came for editing, and so at the end of each css / js file there is a certain url prefix of this kind: www.mysite.ru/wp-content/themes/awesom_theme/css/main.css/?ver=1 . In this case, there was an example with a css file. Given this, any files that really lie on the server, for example, the same main.css style, cannot be edited, and the same old file with ?ver=1 at the end is rolled out to the working version anyway. How to solve this problem? In fact, you need to change several styles on the site and add a little new ones, but I don’t know how to get close to this :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2015-12-23
@Itvanya

github gist
Remove version from scripts and styles links:

function wp_version_js_css($src) {
    if (strpos($src, 'ver='))
    $src = remove_query_arg('ver', $src);
    return $src;
}
add_filter('style_loader_src', 'wp_version_js_css', 9999);
add_filter('script_loader_src', 'wp_version_js_css', 9999);

A
Andrey, 2015-12-23
@VladimirAndreev

in a good way, find the place where the version is set and change it every time the styles or scripts change.
so that no one will definitely have errors due to the caching of styles / scripts and conflicts between old and new versions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question