我可以验证这是否适用于我,它看起来很像您提供的代码。
也许您正在其他地方定义脚本。你能给它一个新的句柄名称来检查吗(\'custom-xyz\')?
此外,您是否可以测试filemtime 看看它输出了什么?我添加了一个“v“在它前面以防它回来false.
$ver = "v" . filemtime( get_stylesheet_directory().\'/js/custom.min.js\' );
wp_register_script( \'custom\',
get_stylesheet_directory_uri() . \'/js/custom.min.js\',
array( \'jquery\',\'modernizr\' ),
$ver,
true);
wp_enqueue_script( \'custom\' );
如果由于奇怪的原因,您在注册时无法使其正常工作,您可以使用
script_loader_tag 还有一些正则表达式或
str_replace.
wp_register_script( \'custom\',
get_stylesheet_directory_uri() . \'/js/custom.min.js\',
array( \'jquery\',\'modernizr\' ),
\'%%CACHE_BUSTER%%\',
true);
wp_enqueue_script( \'custom\' );
function script_tag_cache_buster( $tag, $handle, $src ) {
if ( \'custom\' === $handle ) {
return str_replace( \'%%CACHE_BUSTER%%\', "v" . filemtime( get_stylesheet_directory().\'/js/custom.min.js\'), $tag );
}
return $tag;
}
add_filter( \'script_loader_tag\', \'script_tag_cache_buster\', 10, 3 );