Trying to add versioning using filemtime but fail

Asked
Active3 hr before
Viewed126 times

5 Answers

usingtrying
90%

@ArtisticPhoenix: yet php can read the file, enqueue the script via Wordpress... shouldn't it be able to read the file time just as well? Do you know if there is a way to check if it is a permission problem via php? – nico Dec 21 '16 at 8:22 , 1 yes, I needed it for filemtime but not for wp_enqueue_script. Now I've separated the two, as I described here, answering my own question. – nico Dec 21 '16 at 16:12 ,I'm trying to automatically add versioning to my scripts using filemtime, but get the following error message:, I thought this had failed too, but I was wrong, I had messed up while commenting out parts. This worked. Thanks! Funny how I found examples out there using the _uri Wordpress thingy. – nico Dec 21 '16 at 8:42

You should use the real path instead:

$myfile = get_template_directory_uri().
'/js/script.js';
$realpath = get_template_directory().
'/js/script.js';
wp_enqueue_script('mywebsite-script', $myfile, array('jquery'), filemtime($realpath), true);
88%

It's because you're retrieving it via URL, but filemtime() requires a path. Use get_stylesheet_directory() instead. That returns a path:, I feel bad about rejecting a paper during review ,Please be sure to answer the question. Provide details and share your research!,Warning: filemtime(): stat failed for.....

It's because you're retrieving it via URL, but filemtime() requires a path. Use get_stylesheet_directory() instead. That returns a path:

function pro_styles() {
   wp_enqueue_style('child-style', get_stylesheet_directory_uri().
      '/child-style.css', array(), filemtime(get_stylesheet_directory().
         '/child-style.css'), 'all');
}

add_action('wp_enqueue_scripts', 'pro_styles');
load more v
72%

This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed. , Returns the time the file was last modified, or false on failure. The time is returned as a Unix timestamp, which is suitable for the date() function. ,Note that time resolution may differ from one file system to another.,As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to Supported Protocols and Wrappers to determine which wrappers support stat() family of functionality.

load more v
65%

For those who uses WooThemes Canvas, child theme, and want to automatically add version to custom.css file, here is the code (put it in your functions.php):,The code above is used for my custom css-class. (I dont use the default css), but can easily be amended of course to work along with the stylesheet_url as well., John Permalink to comment# February 13, 2014 Hello guys! For those who uses WooThemes Canvas, child theme, and want to automatically add version to custom.css file, here is the code (put it in your functions.php): View in Pastie.org Thanks to Tiago Noronha, for WooThemes Support Team. Cheers, Reply , Save my name, email, and website in this browser for the next time I comment.

WordPress:

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="screen" />

bbPress:

<link rel="stylesheet" href="<?php bb_stylesheet_uri(); echo '?' . filemtime( bb_get_active_theme_directory() . '/style.css'); ?>" type="text/css" media="screen" />
load more v
75%

which version are you reverting back to? Think 1.8 was fine for me but now I cant find the file to downgrade to that version,Other people confirms the latest version fixes this problem.,I’m having a problem using this plugin. Auto updated to version 1.9 and got critical error on my site, deactivated the plugin and site was fine, tried to roll back the version but still not fixing my problem. Even using 1.9.3-3 I’m still getting this error. have just deactivated the plugin for now but have some styling issues at the moment ,This will work until the plugin is updated and the file is overwritten, but hopefully at that point the variable will be fixed and working properly.

My site auto-upgraded to 1.9, had a compile error with the plugin, and went down as a result. It’s hosted with WordPress.com so I can’t imagine the hosting or ops setup is an issue. Error also doesn’t look to be an interaction with any plugin or theme, since the error seems to be contained to the wp-less folder – but I could totally be wrong there.

Current theme: Stack Child(version 10.5 .21)
Current plugin: WP LESS(version 1.9 .0)
PHP version 7.3 .30

Error Details
   ===
   === === === =
   An error of type E_COMPILE_ERROR was caused in line 50 of the file / srv / htdocs / wp - content / plugins / wp - less / lib / Plugin.class.php.Error message: require(): Failed opening required '/srv/htdocs/wp-content/plugins/wp-less/lib/../vendor/wikimedia/less.php/lessc.inc.php'(include_path = '/:.')

Other "using-trying" queries related to "Trying to add versioning using filemtime but fail"