我在functions.php中的样式队列不起作用吗?

发布于 2025-01-23 10:07:55 字数 525 浏览 2 评论 0原文

我正在创建一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与之呼应 2025-01-30 10:07:55

您是否想将CSS/JS纳入来自另一个现有主题的儿童主题?除非您从头开始构建自己的主题,否则 Child Themes 是首选练习以扩展现有主题(更新安全)。

如果您在子主题中,则可能需要考虑两个函数:

  • ()访问parent tremy path
  • get_template_directory()get_template_directory_uriget_stylesheet_directory_uri()参考儿童主题路径

ps。:您可能需要检查是否有多个函数注册了wp_enque_scripts具有相同名称的CSS/JS。如果是这样,请尝试更改主风格响应式风格custom_scriptADD_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() or get_template_directory_uri() to refer to the parent theme path
  • get_stylesheet_directory or get_stylesheet_directory_uri() to refer to the child theme path

PS.: 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 alter main-styles, responsive-styles, custom_script or the optional priority parameter for add_action as described in the function documentation.

那支青花 2025-01-30 10:07:55

它对我的工作。

function add_css_js(){

// Load css 

wp_enqueue_style('style',get_template_directory_uri().'/assets/css/style.css',array(),'1.0.0','all'); 
    
//load JS

wp_enqueue_script('bootstrap',get_template_directory_uri().'/assets/js/bootstrap.min.js',array('jquery'),'1.0.0',true);

}add_action('wp_enqueue_scripts','add_css_js');

Its work for me.

function add_css_js(){

// Load css 

wp_enqueue_style('style',get_template_directory_uri().'/assets/css/style.css',array(),'1.0.0','all'); 
    
//load JS

wp_enqueue_script('bootstrap',get_template_directory_uri().'/assets/js/bootstrap.min.js',array('jquery'),'1.0.0',true);

}add_action('wp_enqueue_scripts','add_css_js');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文