admin管理员组文章数量:1404923
I am trying to change the stylesheet file version using the filemtime()
function with the wp_enqueue_style
with the following snippet
function pro_styles()
{
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() .'/child-style.css', array(), filemtime(get_stylesheet_directory_uri() .'/child-style.css'), 'all' );
}
add_action( 'wp_enqueue_scripts', 'pro_styles' );
but it is throwing a warning
Warning: filemtime(): stat failed for.....
While i am sure that the file exists
I am trying to change the stylesheet file version using the filemtime()
function with the wp_enqueue_style
with the following snippet
function pro_styles()
{
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() .'/child-style.css', array(), filemtime(get_stylesheet_directory_uri() .'/child-style.css'), 'all' );
}
add_action( 'wp_enqueue_scripts', 'pro_styles' );
but it is throwing a warning
Warning: filemtime(): stat failed for.....
While i am sure that the file exists
Share Improve this question asked Aug 9, 2017 at 9:44 Mohamed OmarMohamed Omar 5191 gold badge5 silver badges17 bronze badges2 Answers
Reset to default 29It'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' );
Just to expand on Jacob Peattie Answer for people that have CSS file in a custom plugin, you can use
filemtime( plugin_dir_path(dirname(__FILE__)).'plugin-folder/css-file-path.css' )
本文标签: theme developmentGetting failure when using filemtime() with wpenqueuestyle
版权声明:本文标题:theme development - Getting failure when using filemtime() with wp_enqueue_style 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744865952a2629345.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论