【问题标题】:CSS File in subforlder of theme not working wordpress?主题子文件夹中的 CSS 文件无法使用 wordpress?
【发布时间】:2017-01-23 20:51:02
【问题描述】:

我在搜索了很多东西后问了这个问题,但任何技巧和答案都不起作用。我是新手,创建了自己的自定义主题。我在我的主题目录中上传自定义字体很棒,如下所示

  • -Gohilar-字体
  • --CSS
  • ---gohilar-font-embedded.css
  • --字体
  • ---gohilar-font.woff

现在的问题是,当我将此 css 文件链接到我的 header.php 时,即使我尝试了许多站点中的所有建议,它也没有链接........但是它在我的本地计算机上正常工作,即 localhost

我在header.php的header下添加了css的代码,如下

  <link rel="stylesheet" href="<?php echo esc_url( get_template_directory_uri() ); ?>/gohilar-font/css/gohilar-font-embedded.css">

如果我链接 http://newser.in/wp-content/themes/Gohilar/gohilar-font/css/gohilar-font-embedded.css 没有正确打开并显示 404 错误

【问题讨论】:

  • 会不会是你的新服务器区分大小写?即“Gohilar-font”与“gohilar-font”不同......但如果您的链接在您的浏览器中不起作用,那么它肯定不会在 css 文件中起作用。因此,您需要找出字体 css 文件的正确 URL 路径...您需要检查的另一件事是,在“gohilar-font-embedded.css”中,如何包含/导入实际字体“gohilar-font .woff" ?
  • 区分大小写!那是我从没想过……你是对的……现在它起作用了????现在我注意我不会再犯错了......谢谢你

标签: php css wordpress


【解决方案1】:

包含 css 文件的推荐方法是使用 wp_enqueue_style。只需将以下代码添加到您的 function.php 并调整文件名和路径即可。

// load bootstrap css
wp_enqueue_style( '_tk-bootstrap', get_template_directory_uri() . '/includes/resources/bootstrap/css/bootstrap.min.css' );

来源:https://developer.wordpress.org/reference/functions/wp_enqueue_style/

【讨论】:

  • 好的,我这样做.....从 header.php 中删除并根据您的代码添加到 function.php ...谢谢?为此
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-08
  • 1970-01-01
  • 2018-12-09
  • 2018-04-07
  • 2015-11-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多