Not to long ago when I had to enqueue a style CSS file or a js file in a child theme I would add a file version number manually, but than when I make some changes to those files and I refresh the browser the changes were not applied and that was normal, because browsers cache stylesheets (`style.css`) and scripts (`main.js`) to improve load times. When you update a file, such as `style.css` or `main.js`, the browser might still use the cached version, ignoring your updates.
Now thanks to advice I got from my friend ChatGPT I'm enqueuing the files using the PHP function filetime() which retrieves the last modified timestamp of the file. By using this timestamp as the version number in `wp_enqueue_style` and `wp_enqueue_script`, the browser sees the version as different whenever the file changes. This forces the browser to fetch the updated file, avoiding caching issues
```php
function child_styles_and_scripts() {
$child_style_version = filemtime( get_stylesheet_directory() . '/style.css' );
wp_enqueue_style(
'child-theme-style',
get_stylesheet_directory_uri() . '/style.css',
[
'child-theme-style',
],
$child_style_version
);
$child_js_version = filemtime( get_stylesheet_directory() . '/main.js' );
wp_enqueue_script(
'main',
get_stylesheet_directory_uri() . '/main.js',
array(),
$child_js_version
);
}
add_action( 'wp_enqueue_scripts', 'child_styles_and_scripts', 20 );
```