My wordpress website is not updating the stylesheet its using instead of style.css it is showing "style.css?ver=3.8.3"
I want to know why is this happening and where does this version thingie come from since I've checked both via admin panel and the ftp and have reset cache but still its getting its styles from some other version of the styelsheet.
It would be really helpful if someone points out the logic behing this. Many Thanks!
You have to set the '$ver' parameter to 'null' in the call to style-sheet in your theme files
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
Add this code to the functions.php file of your WordPress theme
function remove_cssjs_query_string( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_query_string', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_query_string', 10, 2 );
This code will remove query strings (?ver=) parameter from all the CSS and JS files on your site.
add_filter( 'style_loader_src', 'remove_cssjs_query_string', 10, 2 );
Above line removes query strings from all CSS files
add_filter( 'script_loader_src', 'remove_cssjs_query_string', 10, 2 );
Above line removes query strings from all JS files
Hope it helps :)
Source : http://belnad.com/remove-ver-query-string-wordpress-css-js-files/
Related
I am trying to edit the styles of the Woocommerce checkout page that is coming from style.dev.css. I tried to copy the file to my child theme directory and made the changes in the new child file. However, it seems that the page is still loading the original file and not the theme file The reason I am not doing my edits in the style.css child file is that most selectors have !important and don't want to do heavy overwriting. Does anyone know what I am missing, please?
The documentation of WooCommerce could help you acheive what you are looking for.
WooCommerce - Disable the default stylesheet
Disable all stylesheets
WooCommerce enqueues 3 stylesheets by default. You can disable them all with the following snippet:
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
Disable specific stylesheets
If you want to disable specific stylesheets (i.e, if you do not want to include the handheld stylesheet), you can use the following:
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] );
unset( $enqueue_styles['woocommerce-layout'] );
unset( $enqueue_styles['woocommerce-smallscreen'] );
return $enqueue_styles;
}
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
Then enqueue your own stylesheet like so:
function wp_enqueue_woocommerce_style(){
wp_register_style( 'mytheme-woocommerce', get_stylesheet_directory_uri() . '/css/woocommerce.css' );
if ( class_exists( 'woocommerce' ) ) {
wp_enqueue_style( 'mytheme-woocommerce' );
}
}
add_action( 'wp_enqueue_scripts', 'wp_enqueue_woocommerce_style' );
I am trying, essentially, to add the ?ver=1.0 tag to the end of my stylesheet, which I have included in my child theme's function file (enqueued). I have read the documentation in the codex but it does not seem to be applying in the source code, and it is not updating/cache breaking as intended when I apply updates.
The stylesheet itself is being included, however, the version is not applying, so I'm somewhat at a loose end here.
This is my current code:
add_action( 'wp_enqueue_scripts', 'kl_child_scripts',11 );
function kl_child_scripts() {
wp_deregister_style( 'kallyas-styles' );
wp_enqueue_style( 'kallyas-styles', get_template_directory_uri().'/style.css', '' , ZN_FW_VERSION );
wp_enqueue_style( 'kallyas-child', get_stylesheet_uri(), array('kallyas-styles') , filemtime(get_stylesheet_directory() . '/style.css'));
N.B. It is the last line to which I am trying to apply the version. (kallyas-child). The previous line (kallyas-styles) does appear to have some form of version ZN_FW_VERSION, but that does not produce the desired effect.
filemtime(get_stylesheet_directory() . '/style.css') is intended to break cache and update the version number each time the file is saved. Edit: I do, now, believe that this code does in fact work, but the theme (as it is a pre-build) is preventing it from applying properly. I will update if and when I figure this out, hoping to get to talk to the theme developers.
The issue is that your are using filemtime which return an int and you should have a string. As you can read in the documentation :
$ver
(string|bool|null) (Optional) String specifying stylesheet
version number, if it has one, which is added to the URL as a query
string for cache busting purposes. If version is set to false, a
version number is automatically added equal to current installed
WordPress version. If set to null, no version is added. Default value:
false
so you may try this :
add_action( 'wp_enqueue_scripts', 'kl_child_scripts',11 );
function kl_child_scripts() {
wp_deregister_style( 'kallyas-styles' );
wp_enqueue_style( 'kallyas-styles', get_template_directory_uri().'/style.css', '' , ZN_FW_VERSION );
wp_enqueue_style( 'kallyas-child', get_stylesheet_uri(), array('kallyas-styles') , strval(filemtime(get_stylesheet_directory() . '/style.css')));
I added the strval that will convert the int to string
Use below code
define('ZN_FW_VERSION','1.0');
add_action( 'wp_enqueue_scripts', 'kl_child_scripts',11 );
function kl_child_scripts() {
wp_deregister_style( 'kallyas-styles' );
wp_dequeue_style( 'kallyas-styles' );
wp_enqueue_style( 'kallyas-styles', get_template_directory_uri().'/style.css', array() , ZN_FW_VERSION );
wp_enqueue_style( 'kallyas-child', get_stylesheet_uri(), array('kallyas-styles') , ZN_FW_VERSION);
}
in functions.php I added
wp_enqueue_style( 'kallyas-child',
get_stylesheet_directory_uri() . '/style.css',
array( 'kallyas-styles' ),
filemtime(__DIR__.'/style.css')
);
tested it at tmp.demos.rent-a-ninja.org
worked with divi theme
I need to change the wordpress website theme for logged in users. I figured this code:
require_once (ABSPATH . WPINC . '/pluggable.php');
add_filter( 'template', 'change_theme_template' );
add_filter( 'stylesheet', 'change_theme_template' );
function change_theme_template( $template ) {
if ( is_user_logged_in() ) :\
$template = 'twentyfifteen';
endif;
return $template;
}
But it works only for parent themes, it does not work for child theme. I can't find a function to make it work with children. Is there a way to do it? Thank you
I have a wordpress site using the W3 cache plugin with MaxCDN and Cloudlfare. I ran a few different speed tests and one common suggestion is to "Remove query strings from static resources". I download a plugin and cleared my cache everywhere but still got this message.
function vmf_remove_script_version( $src ) {
if ( strpos( $src, 'ver=' ) ) {
$src = remove_query_arg( 'ver', $src );
}
return $src;
}
add_filter( 'script_loader_src', 'vmf_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', 'vmf_remove_script_version', 15, 1 );
After some closer inspection, turns out all the files the speedtests refer to end in ?x81224 (of which there's 50+ files). So I modified the code to the below but still no fix!
function remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) ) {
$src = remove_query_arg( 'ver', $src );
}elseif( strpos( $src, '?x' ) ) {
$src = str_replace('?x81224','',$src);
//remove_query_arg( 'x', $src ); <- thought this wouldn't work because there's no = sign
}
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
Does anyone have any suggestions on how I can fix this?
First of all it is NOT a good idea to remove the ?ver=... query argument. This version is usually static and should only be updated if you change a script.
Your clients save scripts in their local browser history as well as caching Plugins may save this scripts server side. If the version is updated properly the new scripts are delivered. If you remove the ver query argument outdated scripts will be delivered to your clients (maybe for a long time) which causes a lot of troubles and client complaints. Don't do it.
Furthermore there are two problems I recognize with your script:
1) The remove filter priority should be latest so that it is not overwritten by other Plugins therefore set argument 4 to 100 (https://developer.wordpress.org/reference/functions/add_filter/)
function remove_cssjs_ver( $src ) {
if( strpos( $src, '?x' ) ) {
$src = str_replace('?x81224','',$src);
}
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 100, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 100, 2 );
2) Where does ?x81224 come from? Find the Plugin/Function which creates this strange appendix and find out why. It looks like a custom made idea as replacement for the "ver" query argument.
In general I would say it is not a good idea to remove the query strings from static resources as usually there is a good reason for those. Do not know why they recommend it. If the file is cached with query string it will not slow down the site (or at least I can not think of a reason why).
I am using a wordpress theme, and the css file uploads with version number:
style.css?ver=1.2.8
The problem is that when i change the css file, the browser keep loading the file without my changes. I can see that the changes were saved on the server, but nothing help to load the right file.
I tried:
function remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
But everything disappeared.
I read the other topics on the subject but nothing helped.
Thank you.
That below given code may help you.
function vc_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' . get_bloginfo( 'version' ) ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
Taken from https://wordpress.stackexchange.com/questions/132282/removing-wordpress-version-number-from-included-files
That works for me, hope it will work for you as well.
Add this code to the functions.php of your theme.
function remove_file_version($src){
return preg_replace("/\?ver=[0-9.]+/", "", $src);
}
add_filter('style_loader_src', 'remove_file_version', 100);
add_filter('script_loader_src', 'remove_file_version', 100);