Last active
April 8, 2018 21:45
-
-
Save dmhendricks/4d7c5eb620978dee55536742c2ec1955 to your computer and use it in GitHub Desktop.
Remove script versions from enqueued scripts. #wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove script versions from frontend static scripts. | |
* Place this code in your child theme's functions.php OR use the plugin below. | |
*/ | |
add_filter( 'style_loader_src', 'myprefix_remove_script_versions', 9999 ); | |
add_filter( 'script_loader_src', 'myprefix_remove_script_versions', 9999 ); | |
function myprefix_remove_script_versions( $src ) { | |
if ( strpos( $src, 'ver=' ) ) $src = remove_query_arg( 'ver', $src ); | |
return $src; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @wordpress-plugin | |
* Plugin Name: Remove Script Versions | |
* Plugin URI: https://gist.github.com/dmhendricks/4d7c5eb620978dee55536742c2ec1955 | |
* Description: Remove the script versions from frontend scripts. | |
* Version: 1.0.0 | |
* Author: Daniel M. Hendricks | |
* Author URI: https://www.danhendricks.com | |
* License: GPL-2.0 | |
* License URI: https://opensource.org/licenses/GPL-2.0 | |
*/ | |
class Remove_Script_Versions { | |
function __construct() { | |
if( !is_admin() ) { | |
add_filter( 'style_loader_src', array( $this, 'remove_script_versions' ), 9999 ); | |
add_filter( 'script_loader_src', array( $this, 'remove_script_versions' ), 9999 ); | |
} | |
} | |
function remove_script_versions( $src ) { | |
if ( strpos( $src, 'ver=' ) ) $src = remove_query_arg( 'ver', $src ); | |
return $src; | |
} | |
} | |
new Remove_Script_Versions(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added a simple plugin for those who prefer or don't want to/can't edit their
functions.php
. Use one or the other.To use the plugin:
wp-content/plugins
namedremove-script-versions
.remove-script-versions.php
.