Skip to main content
Login Join
Snippet · PHP

Remove WordPress Version

Shared by Darshan Chauhan · May 2, 2026

12 views
1 upvote
Back to Snippets

Hides WordPress version from HTML, scripts, and styles to reduce exposure to automated attacks targeting specific WP versions.

// Remove WordPress version
remove_action('wp_head', 'wp_generator');

function remove_wp_version_strings($src) {
    global $wp_version;
    parse_str(parse_url($src, PHP_URL_QUERY), $query);
    if (!empty($query['ver']) && $query['ver'] === $wp_version) {
        $src = remove_query_arg('ver', $src);
    }
    return $src;
}
add_filter('script_loader_src', 'remove_wp_version_strings');
add_filter('style_loader_src', 'remove_wp_version_strings');
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments