Removes WordPress Version Number

Removes WordPress version number from metadata, scripts, and styles for security.

PHP
/**
 * Snippet Name:     Removes WordPress version number
 * Snippet Author:   coding-bunny.com
 * Description:      Removes WordPress version number from metadata, scripts, and styles for security.
 */

// Remove WordPress version from meta tag in the site header.
function cb_remove_wp_version_meta() {
    return '';
}
add_filter( 'the_generator', 'cb_remove_wp_version_meta' );

// Remove WordPress version from enqueued scripts and styles.
function cb_remove_wp_version_from_assets( $src ) {
    if ( strpos( $src, 'ver=' ) ) {
        $src = remove_query_arg( 'ver', $src );
    }
    return $src;
}
add_filter( 'style_loader_src', 'cb_remove_wp_version_from_assets', 9999 );
add_filter( 'script_loader_src', 'cb_remove_wp_version_from_assets', 9999 );

How To Implement This Solution?

Leave a Reply

Your email address will not be published. Required fields are marked *

My Agile Privacy
This site uses technical and profiling cookies. You can accept, decline or customize cookies by pressing the desired buttons. By closing this policy you will continue without accepting.

Need help?

Choose one of the following options:

Powered by CodingBunny