Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This plugin hides all WP versions from the head of the document and anables auto updates. It could be placed in /wp-content/mu-plugin folder
<?php
/**
* @package CD Hide WordPress Version
* @version 1.0
*/
/*
Plugin Name: CD Hide WordPress Version
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This plugin removes the version number from WordPress pages
Author: Carlo Daniele
Version: 1.0
Author URI: http://carlodaniele.it/en/
*/
/**
* Filter whether to automatically update core, a plugin, a theme, or a language.
* Defined in /wp-admin/includes/class-wp-upgrader.php
* The dynamic portion of the hook name, `$type`, refers to the type of update
* being checked. Can be 'core', 'theme', 'plugin', or 'translation'.
*
* @param bool $update Whether to update.
* @param object $item The update offer.
*
*/
add_filter( 'auto_update_core', '__return_true' );
add_filter( 'auto_update_theme', '__return_true' );
add_filter( 'auto_update_plugin', '__return_true' );
/**
* Filter the output of the XHTML generator tag for display
*
* @param $generator_type string The generator output.
* @param $type string The type of generator to output. Accepts 'html', 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
*
* @return string $src
*
* @link https://developer.wordpress.org/reference/hooks/the_generator/
*/
function cd_remove_generator() {
return '';
}
add_filter('the_generator', 'cd_remove_generator');
/**
* Hide WP version strings from scripts and styles
*
* @param string $src The source URL of the enqueued style
* @return string $src
*
* @link https://developer.wordpress.org/reference/hooks/style_loader_src/
* @link https://developer.wordpress.org/reference/hooks/script_loader_src/
*/
function cd_remove_script_style_wp_ver( $src ) {
global $wp_version;
// parses query variables into string
$query_string = parse_url( $src, PHP_URL_QUERY );
// store variables into $query array
parse_str( $query_string, $query_vars );
// check if script version is equal to WP version
if ( !empty($query_vars['ver']) && $query_vars['ver'] === $wp_version ) {
$src = remove_query_arg( 'ver', $src );
}
return $src;
}
add_filter( 'style_loader_src', 'cd_remove_script_style_wp_ver' );
add_filter( 'script_loader_src', 'cd_remove_script_style_wp_ver' );
@mikheilangel
Copy link

mikheilangel commented May 21, 2020

Hi @carlodaniele,
I don't know if there is any incompatibility with the latest version of wordpress (5.4.1) but I recently used this mu-plugins, and it happened three times that after a few hours or at most 1 day, there were automatically update all wordpress plugins, except the plugins that have been updated for a few hours.
It also happened having activated the "WordPress Auto-updates" plugin by setting everything manually.

This is the only mu-plugins I used, I deleted the folder, and after a few days it hasn't happened to me anymore, even by deactivating the "WordPress Auto-updates" plugin.

I hope it will help to solve the problem.

Thanks anyway for creating this plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment