我在functions.php中的样式队列不起作用吗?
我正在创建一个WordPress主题,我的样式队列不起作用。
这是functions.php中的队列,
function style_script_enqueue(){
wp_enqueue_style('main-styles', get_template_directory_uri() . '/css/main.css' );
wp_enqueue_style('responsive-styles', get_template_directory_uri() .
'/css/responsive.css' );
wp_enqueue_script('custom_script', get_template_directory_uri() . '/js/script.js', array(), '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'style_script_enqueue');
我也称为wp_head(); ,wp_footer(); ,并检查了目录。
I am creating a wordpress theme and my styles queue is not working.
This is the queue in functions.php
function style_script_enqueue(){
wp_enqueue_style('main-styles', get_template_directory_uri() . '/css/main.css' );
wp_enqueue_style('responsive-styles', get_template_directory_uri() .
'/css/responsive.css' );
wp_enqueue_script('custom_script', get_template_directory_uri() . '/js/script.js', array(), '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'style_script_enqueue');
I have also called wp_head(); , wp_footer(); , and checked the directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否想将CSS/JS纳入来自另一个现有主题的儿童主题?除非您从头开始构建自己的主题,否则 Child Themes 是首选练习以扩展现有主题(更新安全)。
如果您在子主题中,则可能需要考虑两个函数:
get_template_directory()
或get_template_directory_uri
或get_stylesheet_directory_uri()
参考儿童主题路径ps。:您可能需要检查是否有多个函数注册了
wp_enque_scripts
具有相同名称的CSS/JS。如果是这样,请尝试更改主风格
,响应式风格
,custom_script
或ADD_ACTION
的可选优先参数如功能文档。Do you want to enqueue your CSS/JS in a child theme derived from another existing theme? Unless you build your own theme from scratch, child themes are the preferred practice to extend existing themes (update safe).
If you are in a child theme, there are two functions you might want to consider:
get_template_directory()
orget_template_directory_uri()
to refer to the parent theme pathget_stylesheet_directory
orget_stylesheet_directory_uri()
to refer to the child theme pathPS.: You might want to check if there are multiple functions registered for
wp_enqueue_scripts
, which try to enqueue CSS/JS with the identical name. If so, try to altermain-styles
,responsive-styles
,custom_script
or the optional priority parameter foradd_action
as described in the function documentation.它对我的工作。
Its work for me.