首页 > 解决方案 > 字体不在 wordpress 网站上呈现

问题描述

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

我面临的问题是: 在此处输入图像描述

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

在此处输入图像描述

在下面的 urlhttp://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");
}

标签: htmlcsswordpress

解决方案


您有字体文件的路径问题,请在控制台窗口中检查。并在您的样式/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');
}

希望能帮助到你。


推荐阅读