How to remove query strings from fonts?

I have seen this old topic about the same could be possible to give a proper advice in order to do it with the last version of x theme ? thanks

Hi There,

You have to setup the X child theme first: https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57.

After that add the following code under functions.php file locates in your child theme:

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

Hope it helps :slight_smile:

It does not work and the speed is slower :frowning:

Hi Borislav.VD,

I’ve tested this snippet and it’s working fine at my localhost, could you please make sure you have cleared cache on your website in case you have a caching plugin installed and recheck this issue?

If this doesn’t help, then please provide us with WordPress Dashboard login details in a “Secure Note” so we can investigate this issue.

Thanks.

i have another code in htaccess for that but unfortunately it does not work ( the mine and the yours ) over the fonts of the plugins for example the superfly one . How could be possible to avoid them ? thanks

https://mydomain.com/wp-content/plugins/superfly-menu-vlEIrz/img/fonts/icomoon.woff?wehgh4

Hi @Borislav.VD,

In this case, as said above, if still not helping, please share us your admin and FTP credentials so we could check your setup closer and we could identify the problem.

Don’t forget to set it in a secure note.

Thanks.

here you have thanks

Hi there,

The above code is used to remove the version from URL query which is ?ver=, in your font, it has ?wehgh4 instead of ?ver=. You’ll have to enhance your code to include all possible URL query. The provided code is just a basic one to help you get started.

function remove_css_js_ver( $src ) {
	if( strpos( $src, '?ver=' ) ) $src = remove_query_arg( 'ver', $src );
        if( strpos( $src, '?wehgh4' ) ) $src = remove_query_arg( 'wehgh4', $src );
	return $src;
}
add_filter( 'style_loader_src', 'remove_css_js_ver' );
add_filter( 'script_loader_src', 'remove_css_js_ver' );

Please also note that this only works for scripts and CSS loaded through Wordpress enqueue. If any files or URL are added statically, then it can be fixed by editing them manually.

I also checked your site and I don’t see such font, perhaps you already fixed it? Or is it in admin?

You must also clear your caches after every change you made to the code.

Thanks!

IF I remove such behaviour from the last 3 fonts , would be possible to save 0.3 seconds . I attach the waterfall or even doing it , i would not save time ?

Hi there,

It’s not that much noticeable since it always vary depending on existing caches and internet speed. But you may still try it.

But again, if those fonts are pulled from CSS styling then the above code will not work. It’s only applicable for URLs added by WP’s enqueue.

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.