Wordpress - Google 字体无法正常工作/导入 [英] Wordpress - Google fonts not working / importing correctly

查看:32
本文介绍了Wordpress - Google 字体无法正常工作/导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Wordpress 的新手,我正在使用 html5blank 主题导入我的样式表.我注意到 google 字体不适用于 wordpress 网站.

I'm quite new to Wordpress and I'm importing my stylesheets across using the html5blank theme. I've noticed the google fonts aren't applying in the wordpress site.

我的 header.php 文件中有这个链接 -

I have this link in my header.php file -

<link href='https://fonts.googleapis.com/css?family=Merriweather+Sans:100,200,400,700,700i,800,800i' rel='stylesheet' type='text/css' />

在我的 style.css 文件中,我有这个 -

And in my style.css file I have this -

@import url('https://fonts.googleapis.com/css?family=Merriweather+Sans:100,200,400,700,700i,800,800i');

body {
    font-family: "Merriweather Sans", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #333333;
}

正文"规则是否像在前端情况下一样适用于 Wordpress?或者还有什么我需要添加/更改的吗?

Do 'body' rules apply in Wordpress in the same way they would in a front-end situation? Or is there something else I need to add/change?

推荐答案

你是在告诉 wp 加载 stlye.css 文件吗?

Are you telling wp to load the stlye.css file?

尝试对您的 functions.php 文件执行此操作:

Try doing this to your functions.php file:

function load_styles() {
  wp_enqueue_style('styles', 'path/to/style.css');
}

其次是(如果您的样式适用于网站的前端):

followed by (if your styles are for the site's front-end):

add_action('wp_enqueue_scripts', 'load_styles');

或(如果您的样式适用于网站的管理面板):

or (if your styles are for the site's admin panel):

add_action('admin_enqueue_scripts', 'load_styles');

此外,您通过执行以下操作添加了两次字体:

Also, you're adding the fonts twice by doing:

<link href='https://fonts.googleapis.com/css?family=Merriweather+Sans:100,200,400,700,700i,800,800i' rel='stylesheet' type='text/css' />

在您的标题和:

@import url('https://fonts.googleapis.com/css?family=Merriweather+Sans:100,200,400,700,700i,800,800i');

在你的 style.css 中

in your style.css

选择其中之一,或者您可以将其添加到您的functions.php文件中的load_styles()"函数:

function load_styles() {
  wp_enqueue_style('styles', 'path/to/style.css');
  wp_enqueue_style('fonts', 'https://fonts.googleapis.com/css?family=Merriweather+Sans:100,200,400,700,700i,800,800i');
}

如果这不起作用,请提供更多信息,例如:

If this doesn't work, please provide more information such as:

  • 浏览器的开发者控制台是否有错误?

  • Are there errors on your browser's developer console?

css 规则是否显示在开发控制台中?

Are the css rules showing up in the dev console?

是否正在加载字体?

这篇关于Wordpress - Google 字体无法正常工作/导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆