Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.77k stars 891 forks source link

Removing `?ver=` from css/js breaks wpseo admin pages #17025

Open Grezvany13 opened 3 years ago

Grezvany13 commented 3 years ago

Please give us a description of what happened.

Admin page of plugin breaks when the ?ver= tag is removed from styles and scripts globally (see reproduction). Both CSS and JS files from the plugin are not loaded anymore, causing the styling and some functionalities to break.

Console returns the error:

admin.php?page=wpseo_dashboard:278 Uncaught TypeError: window.wpseoHelpScoutBeaconConsent is not a function

Please describe what you expected to happen and why.

It should be possible, for security reasons, to remove the version tag from loaded files without breaking anything. By default does WordPress add its own version number, which is a security risk.

How can we reproduce this behavior?

  1. Add the following code in functions.php of the active theme, or through a plugin like Code Snippets:
    // remove version number from loaded CSS and JS
    function jd_remove_src_version($src) {
    if (strpos($src, '?ver=')) {
        $src = remove_query_arg('ver', $src);
        return $src;
    }
    }
    add_filter('script_loader_src', 'jd_remove_src_version');
    add_filter('style_loader_src', 'jd_remove_src_version');
  2. Go to /wp-admin/admin.php?page=wpseo_dashboard
  3. Notice the styling being missing and an error in the console.

Technical info

Used versions

Djennez commented 3 years ago

Looks like that is limited to the select2 components (at least for the General page of Yoast).

I am not sure if this is expected to work, so I am also not sure if this is something that'll be considered to change. So I would advise not to do this for our plugin files.