1

I'm registering my javascript files for Wordpress in my functions file as so:

if( !function_exists( "theme_js" ) ) {  
  function theme_js(){    

wp_register_script('wpbs-scripts', 
          get_template_directory_uri() . '/library/js/min/scripts.min.js', 
          array('jquery'), 
          '1.43',
          'true' );

wp_enqueue_script('wpbs-scripts');
  }
}
add_action( 'wp_enqueue_scripts', 'theme_js' );

In my production environment they are executing properly with the version number as you would expect "scripts.min.js/?ver=1.43. But on the live server the version numbers are a 32 digit string of random numbers and lowercase letters like this "scripts.min.js/?ver=65cat8def2cbb5f145751979a4b2b7cf".

I have no idea what is causing this and it seems to have happened only recently. I started noticing that people needed to refresh the site to see changes.

  • 3
    Have you tried disabling all plugins and/or using one of the default themes, and then seeing if this is still occuring? – czerspalace Jan 22 '16 at 21:54
  • wat plugins have u enabled? – Pmpr Jan 23 '16 at 0:40
  • Have u tried deregistering the handle, using wp_deregister_script before using wp_register_script? – Pmpr Jan 23 '16 at 0:46
  • I apologize for the late response on this. It looks like the Wordfence plugin is to blame. I can't find anything in the settings to control this either. – brandozz Feb 3 '16 at 17:02
1

I have not directly an answer to solve your issue as it (please take a look at the edit part I add),
but this codesnippet (function) could maybe help you to solve the version issues for .js as well for .css files.

/**
 * Remove query (output)string from .js / .css
 * Using filters
 */
function wpse215386_remove_script_version( $src ){
  $parts = explode( '?ver', $src );
  return $parts[0];
}
// for .js files
add_filter( 'script_loader_src', 'wpse215386_remove_script_version', 15, 1 );
// for .css files
add_filter( 'style_loader_src', 'wpse215386_remove_script_version', 15, 1 );

Please leave version numbers away when you use enqueue if there is no specific reason to use them. Add .js filles to the footer to help your pages loading faster, for reference see $in_footer.

Think about updates/upgrades and what can/will happen when versions change and not match with the version(s) you use in your function(s).

The function above has also another effect(a positive one), namely helping to make files easier cacheable. See my answer here for some explanation.

Codex: register and enqueue the correct way to prevent issues.


Edit

One of the reasons could be a security or cache pluging (or maybe even both), so disabling plugins to see which could cause the problem. Enable debug in wp-config.php to see if it drops error messages in the logfile.(if correct configurated the log file will be in the wp-content folder.

0

Don't you need to be using wp_enqueue_script instead of wp_register_script? What I get from the wp_enqueue_script codex page the correct way to add scripts dependant on jQuery is:

<?php

  function my_scripts_method() {
    wp_enqueue_script(
      'custom-script',
      get_stylesheet_directory_uri() . '/js/custom_script.js',
      array( 'jquery' )
  );
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

?>

This may be what's causing you issues.

  • 1
    I'm actually registering and then using wp_enqueue_scripts. I believe that is the proper way to handle it. I've edited my code above to show my entire script. – brandozz Jan 22 '16 at 21:47
0

The WordPress plugin Wordfence(ver. 6.0.22) was causing this issue. To fix this, go to "Options" and uncheck "Hide WordPress Version".

  • 1
    So it was, as I mentioned, a security issue, good to hear you solved the problem. – Charles Feb 4 '16 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.