Create a gist now

Instantly share code, notes, and snippets.

Embed
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment