Created
May 2, 2026 02:04
-
-
Save mrkdevelopment/8dbb21a2e54cb1d553e4cf1b5b03f95b to your computer and use it in GitHub Desktop.
A snippet of code to hide the version numbers of WordPress and all plugins and themes in your setup.
This file contains hidden or 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
| // 1. Remove the version number from the site's <head> (Meta Generator) | |
| remove_action( 'wp_head', 'wp_generator' ); | |
| // 2. Remove the version number from RSS feeds | |
| add_filter( 'the_generator', '__return_empty_string' ); | |
| /** | |
| * Replace all script and style version numbers with a Year-Month string | |
| */ | |
| function replace_version_with_month( $src ) { | |
| // Check if the URL contains a 'ver=' parameter | |
| if ( strpos( $src, 'ver=' ) ) { | |
| // Generate the current year and month (e.g., "202604" for April 2026) | |
| $monthly_ver = date( 'Ym' ); | |
| // Strip the original plugin/theme version | |
| $src = remove_query_arg( 'ver', $src ); | |
| // Append our custom monthly version | |
| $src = add_query_arg( 'ver', $monthly_ver, $src ); | |
| } | |
| return $src; | |
| } | |
| // Use a higher priority (15) to ensure this runs after plugins try to add their versions | |
| add_filter( 'script_loader_src', 'replace_version_with_month', 15, 1 ); | |
| add_filter( 'style_loader_src', 'replace_version_with_month', 15, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment