User Agents

Web browsers and everyday web tech, explained

Remove Version String from WordPress URLs

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

WordPress adds a version number (like ?ver=6.4.2) to the URLs of your stylesheets and scripts. This is used for cache busting, but it can also expose your WordPress version to anyone inspecting your site, and some security plugins flag it. Removing it is a small code tweak that improves privacy and cleans up your source code. You'll need access to your theme's functions.php file or a code snippets plugin. This guide shows you how to do it safely.

What You'll Need

  • Access to your WordPress admin dashboard.
  • An FTP client or a file manager in your hosting control panel (cPanel, etc.) to edit files.
  • A code editor (like Notepad++ or VS Code) or a text editor.
  • Basic understanding of PHP (just enough to copy/paste).
  • Alternatively, a plugin like "Code Snippets" (if you prefer not to edit theme files directly).

Step-by-Step

  1. Backup your site. Before making any code changes, create a full backup of your WordPress files and database. This is essential so you can restore if something goes wrong.
  2. Choose your editing method. You have two safe options:
    • Option A (Recommended): Install and activate the free "Code Snippets" plugin. This lets you add code without touching your theme files, and updates won't overwrite your changes.
    • Option B (Manual): Access your theme's functions.php file via FTP or your hosting file manager. The file is located at /wp-content/themes/your-theme-name/functions.php. Make sure you're using a child theme, or your changes will be lost when you update the parent theme.
  3. Add the code snippet. Copy and paste the following PHP code into your snippets plugin or at the end of your functions.php file (before the closing ?> tag if one exists):
    function remove_wp_version_strings( $src ) {
        if ( strpos( $src, 'ver=' ) ) {
            $src = remove_query_arg( 'ver', $src );
        }
        return $src;
    }
    add_filter( 'script_loader_src', 'remove_wp_version_strings', 15, 1 );
    add_filter( 'style_loader_src', 'remove_wp_version_strings', 15, 1 );
  4. Save and activate. If you're using the Code Snippets plugin, click "Save Changes" and then toggle the snippet to "Active". If you edited functions.php, save the file and upload it back to your server (if you downloaded it).
  5. Clear all caches. Go to your caching plugin (like WP Super Cache, W3 Total Cache, or your hosting's cache) and clear all caches. Also clear your browser cache.
  6. Verify the change. View your site's source code (right-click on the page and select "View Page Source"). Look for stylesheet and script tags. The ?ver=... should be gone. For example, you should see style.css instead of style.css?ver=6.4.2.

Common Mistakes

  • Not using a child theme: Editing the parent theme's functions.php directly means your changes will be lost when you update the theme. Always use a child theme or a code snippets plugin.
  • Forgetting to clear caches: The version string may still appear in cached pages. Clearing all caches (server, plugin, and browser) is essential to see the change.
  • Copying code incorrectly: A missing semicolon or bracket can break your site. Copy the code carefully, and if you're unsure, use a code editor that highlights syntax errors.
  • Removing version strings from ALL URLs: The code above only affects scripts and styles. It does not remove the version from the WordPress generator meta tag (which is a separate fix).

Tips

  • Use a child theme: If you're editing theme files, always use a child theme. This is a WordPress best practice and prevents losing your customizations on theme updates.
  • Test on a staging site: If you have a staging environment, test the code there first before applying it to your live site.
  • Combine with removing the generator tag: For better security through obscurity, also remove the WordPress generator meta tag. Add this to your functions.php:
    remove_action('wp_head', 'wp_generator');
  • Keep a record: If you use the manual method, note down the change in a comment in your functions.php file so you know what it does later.

Troubleshooting

My site is showing a white screen (fatal error). This usually means there's a syntax error in your code. Immediately revert to your backup, or delete the snippet you added. If you can't access the admin, use FTP to remove the code from functions.php.

The version string is still there. First, clear all caches again. If it's still showing, check if your theme or a plugin is adding its own version parameters that aren't filtered by the standard hooks. Some plugins hardcode their own version strings. In that case, you may need to use a more advanced filter or a plugin that handles all script/style sources.

My site loads slower after removing version strings. This is unlikely, but if you notice performance issues, it's probably unrelated. Version strings are not a performance factor.

I'm using a caching plugin and the version string is still in the cached HTML. Clear the cache in your caching plugin, and also purge any server-side cache (like Varnish or CDN).

Frequently Asked Questions

Does removing version strings affect my site's performance?

No, it has no measurable impact on performance. The version string is only used for cache busting; removing it can actually cause browsers to serve stale files if you update your theme or plugins, so be aware of that.

Will this break my site's styling or scripts?

No, the code only removes the query parameter. The file itself is still loaded. However, if you update your theme or plugins, browsers might cache the old files and not fetch the new ones, so you may need to force a cache refresh.

Is this the same as hiding the WordPress version?

Not entirely. Removing version strings from URLs is one step. The version is also displayed in the generator meta tag in the head of your site. To remove that, use the remove_action('wp_head', 'wp_generator'); code shown above.

Can I remove version strings from only certain scripts?

Yes, you can modify the filter to target specific handles. For example, to only remove from the 'jquery' handle, you'd check $handle == 'jquery' inside the function. But the provided code is simpler and works for all.

Will this affect my SEO?

No, search engines do not use the version parameter for ranking. It's a privacy and cleanliness measure, not an SEO one.

Do I need to update this after WordPress updates?

No, the code is independent of the WordPress version and will continue to work after updates. However, if you're editing the theme's functions.php directly, a theme update will overwrite it, so use a child theme or a plugin.