gpt4 book ai didi

css - 在wordpress中添加style.css,正确的方法

转载 作者:太空宇宙 更新时间:2023-11-04 01:26:14 24 4
gpt4 key购买 nike

所以我在 wordpress 主题开发和整个 Web 开发方面都是 super 新手,并且正在尝试了解 WP 生态系统。任何帮助将不胜感激

在浏览一些 WP 教程时,我发现有多种方法可以在 wordpress 中包含 style.css 文件。即,

  1. <?php bloginfo('stylesheet_url'); ?>
  2. <?php echo get_stylesheet_uri(); ?>
  3. <?php echo get_template_directory_uri(); ?>/style.css

header.php中可以添加前3行代码

除此之外,我们还可以使用函数- wp_enqueue_style()

我的问题是,在 wordpress 模板中包含 style.css 的正确方法是什么..

最佳答案

我相信使用 wp_enqueue_style() 是基本的并且更合适。

如果您希望样式表仅在特定页面模板上被引用,那么您可以这样做

if ( is_page_template('template-directory/template-name.php')) {
wp_enqueue_style( 'theme_css', get_template_directory_uri() . '/directory/filename.css');
}

或者如果它不是特定于页面模板,您就可以这样做。

wp_enqueue_style( 'theme_css', get_template_directory_uri() . '/directory/filename.css');

这段代码需要放在您的 functions.php 文件中。在这里阅读更多相关信息 -> https://developer.wordpress.org/themes/basics/including-css-javascript/#stylesheets

您还需要注意引用 css 文件的顺序 -> In which order do CSS stylesheets override?

关于css - 在wordpress中添加style.css,正确的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48043657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com