【问题标题】:Fonts not rendering on wordpress sitewordpress 网站上不显示字体
【发布时间】:2019-12-20 16:13:41
【问题描述】:

我创建了一个纯 html 网站,其中包含一个用 WordPress 开发的博客部分。我使用“PostGrid”插件来显示类似网格的结构,并在 WordPress 中使用帖子部分,允许在该博客部分添加帖子。

我面临的问题是:

在上面的图像中,字体被正确渲染,但不是在第二页。

在以下网址http://localhost/wordpress/home/,我有我所有的博客。在这个页面上,我最多可以添加六个帖子,如果我添加更多博客,那么它将被添加到下一页,因为 WordPress 提供了内置的分页支持。

我在上面的 URL 上添加的博客适合使用自定义字体,但如果我添加更多帖子/博客,它会转到下一页,即:http://localhost/wordpress/home/page/2/,这里字体不会被渲染并显示错误控制台。

获取http://localhost/wordpress/home/page/fonts/Gilroy-Semibold.ttf net::ERR_ABORTED 404(未找到)。

我的字体路径对于帖子的主页和第 2 页是相同的,但在第 2 页上它没有呈现。

我已经尝试了所有解决方案,通过在控制台上添加 css,我还从 WordPress 的 Simple CSS 更改了 css,但它没有加载。

谁能帮我解决这个问题,我会分享代码。

我在 WordPress 的简单 CSS 中使用了下面的 CSS,这对于两个博客页面都是一样的。

@font-face {
    font-family:gilroylight;
    src: url("../fonts/Gilroy-Light.ttf");

  }
@font-face {
    font-family:gilroysemibold;
    src: url("../fonts/Gilroy-Semibold.ttf");
  }
@font-face {
    font-family:keepcalm;
    src: url("../fonts/KEEPCALM-MEDIUM_0.TTF");
}

【问题讨论】:

  • 我是 wordpress 新手,我不知道我应该分享什么代码。所以我添加了我的网页图片。
  • 你是如何添加字体的?加载本地托管字体的最常见方法是通过主题样式表中的 font-face 声明,尽管还有其他可能性(一如既往) - 所以 /wp-content/themes/yourtheme/assets/fonts/fontfile.ext 可能是一个典型的文件位置。
  • 我在 wordpress 的 Simple CSS 中添加了字体。它适用于帖子主页,但不适用于第二页。
  • developer.wordpress.org/themes/basics/main-stylesheet-style-css 最佳/推荐做法是创建一个子主题来进行主题修改。developer.wordpress.org/themes/advanced-topics/child-themes 在我看来,像 Simple CSS 这样的工具已经过时,而不是字体解密的首选位置。跨度>

标签: html css wordpress


【解决方案1】:

字体文件的路径有问题,请在控制台窗口中检查。并更改您的样式/css 中的路径/url。

/* If css and fonts are in same folder*/
@font-face {
    font-family: "CustomFont";
    src: url('CustomFont.ttf');
}

/* If fonts is outside of your css folder*/
@font-face {
    font-family: "CustomFont";
    src: url('../CustomFont.ttf');
}

/* Absolute static path of fonts file*/
@font-face {
    font-family: "CustomFont";
    src: url('file:///C:/Users/Administrator/fonts/CustomFont.ttf');
}

/* Url path of fonts file*/
@font-face {
    font-family: "CustomFont";
    src: url('http://localhost/wordpress/Your-font-folder-path/CustomFont.ttf');
}

希望对你有帮助。

【讨论】:

  • 谢谢您的回答,请告诉我如何在 wordpress.ie URL 字体中添加字体。
  • 尝试将字体样式添加到您的 css 文件中。并将此 css 文件用于所有页面。
【解决方案2】:

在您的样式 CSS 中:根据您的路径 src 和字体系列替换

@font-face {
  font-family: Roboto;
  src: url(http://localhost/wordpress/wp-content/themes/twentyseventeen-child/fonts/Roboto-Regular.ttf);
  font-weight: normal;
}

【讨论】:

  • 感谢您的回答,您能告诉我如何在我的 wordpress 网站中添加这些字体
猜你喜欢
  • 2012-05-14
  • 2021-04-29
  • 1970-01-01
  • 1970-01-01
  • 2019-06-25
  • 2018-06-28
  • 2017-02-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多