1

I'm attempting to modify a WordPress theme so that it appends a version number to a particular stylesheet. This is all done on a local development machine, tested on a staging server, too, for good measure. Following the instructions here: https://www.mojowill.com/developer/get-your-wordpress-css-changes-noticed-immediately/, I added filemtime( get_template_directory() . '/css/main.css' ) into the arguments passed through wp_register_style

From:

wp_register_style('style', get_template_directory_uri() . '/css/style.css', array(), '', 'all');

to

wp_register_style('style', get_template_directory_uri() . '/css/style.css', array(), 'filemtime( get_template_directory_uri() . '/css/style.css'', 'all');

No soap. Viewing the source of the rendered page, I see the stylesheet link has no version appended to it.

I tried pulling the filemtime function out of the $ver slot, and replacing it with a static value like 1.0, and that didn't work, either. Finally, I skipped the $ver argument, and changed the path to a versioned file, like so:

wp_register_style('style', get_template_directory_uri() . '/css/style.css?ver=1.0', array(), '', 'all');

Still nothing. Why would WordPress refuse to acknowledge these updates? No server-side caching or plugins that I could imagine would influence this process. Is there something very simple I'm missing?

Thanks much

James

edit: Here's the entire relevant code block.

function minikit_register_js_and_css() {
    if (!is_admin()) {  
        wp_register_style('style', get_template_directory_uri() . '/css/style.css?ver=1.1', array(), '', 'all');
        wp_enqueue_style('style');
    }
}
2

At long last, I have identified the issue. The theme I was working in used the Minikit theme starter, which has a function that strips version numbers.

function minikit_remove_wp_ver_css_js($src) { if (strpos($src, 'ver=')) $src = remove_query_arg('ver', $src); return $src; }

Naturally, the version numbers returned once I stopped calling this function.

0

Make sure to wp_enqueue_style ('unique-style-name' ).

add_action( 'wp_enqueue_scripts', 'register_plugin_styles' );

function register_plugin_styles() {
    wp_register_style( 'unique-style-name', plugins_url( 'my-plugin/css/plugin.css' ) );
    wp_enqueue_style( 'unique-style-name' );
}
  • Thanks, @jgraup. Good thought, but I'm afraid I'm certain I am using wp_enqueue_style(). Editing original question. – jamesfacts Dec 10 '15 at 20:25
  • It looks like you're hardcoding the version and ignoring the version argument when you register. function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) what happens when you remove it from the url and pass the number as an argument? – jgraup Dec 10 '15 at 20:45
  • wp_register_style('style', get_template_directory_uri() . '/css/style.css', array(), '1.1', 'all'); – jgraup Dec 10 '15 at 20:46
  • No change. I expected the $ver value to be tacked on, so I assumed that passing '' would mean nothing would be appended to the link URL. Taking the hardcoded version out and using the $ver value still doesn't modify the link when the site is rendered: <link rel='stylesheet' id='style-css' href='http://localhost:8888/wp-content/themes/xxxx/css/style.css' type='text/css' media='all' /> – jamesfacts Dec 10 '15 at 20:59
  • what happens when you wp_deregister_script ('style'); wp_register_style('style', get_template_directory_uri() . '/css/xyz.css?ver=youbetterworkorelse');wp_enqueue_style( 'style' );? – jgraup Dec 10 '15 at 21:10
0

Some possibilities:

  • Try a different identifier other than 'style', make it unique to your plugin, something like 'myplugin_styles'
  • Is wp_head() called on you header.php file? Maybe the stylesheet code is hardcoded on the template.
  • Are you running any caching plugins? If so deactivate them.
  • This one is trickier, but are you sure this is the only wp_register_style declaration on your plugin? Maybe is being set again later on the same file or on another file.

Those are the first ideas that come to mind. I hope it helps

  • Thanks, @Felix-Chi. Good suggestions.... no luck so far. FWIW, I'm not working with a plugin, just attempting to force WP to increment the version of the theme's main stylesheet. – jamesfacts Dec 10 '15 at 21:05
  • Oh ok, same principle applies though, some themes add wp_register_style declarations on the theme files like index.php and page.php instead of functions.php. – Felix Dec 10 '15 at 21:14

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.