2

I'm receiving the following filemtime() warning:

Warning: filemtime(): stat failed for https://testing.local/wp-content/plugins/test-social-icons/css/style.css in /app/public/wp-content/plugins/zoo-social-icons/zoo-social-icons.php on line 29

Here's how I'm enqueuing the stylesheet within my plugin:

function test_styles_scripts() {
   $dir = plugin_dir_url(__FILE__);
   wp_enqueue_style( 'test-style', $dir . 'css/style.css', array(), filemtime( $dir . 'css/style.css' ) );
}
add_action( 'wp_enqueue_scripts', 'test_styles_scripts' );

The stylesheet is correctly enqueuing. Why am I getting this warning?

2
  • 3
    Sally's comment here was that the first plugin_dir_path() needed to be plugin_dir_url(). The second one, for filemtime(), still needs to be plugin_dir_path(), because filemtime() requires a path, not a URL, but the browser requires a URL, which is what the first one is for. Mar 11, 2020 at 13:57
  • Boom, that works! Thank you @JacobPeattie. Please post your answer and I'll mark it as accepted.
    – Sam
    Mar 11, 2020 at 14:06

1 Answer 1

0

Restating the answer from @JacobPeattie in the comments above.

filemtime() requires a path, not a URL

Therefore use plugin_dir_path(__FILE__).

The full string for properly printing the cache-busting part of the version number at the end of the asset would be filemtime( plugin_dir_path(__FILE__)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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