简体   繁体   English

在Wordpress中手动加载Awesome字体

[英]Load Font Awesome manually in Wordpress

I am fairly new to Wordpress. 我对Wordpress相当陌生。 I am trying to add a Font Awesome to the "list" of my wp_enqueue style sheets. 我试图将真棒字体添加到wp_enqueue样式表的“列表”中。 When I add it by using the CDN link, it works perfectly. 当我使用CDN链接添加它时,它可以完美运行。 However, when I add the stylesheet manually, it shows boxes around the area where the icon should be (as if there is nothing or hasn't been added). 但是,当我手动添加样式表时,它会在图标应放置的区域周围显示框(好像什么也没有添加或未添加)。

Here is my current code which is NOT working 这是我当前的代码不起作用

 wp_enqueue_style('font-awesome', get_template_directory_uri() . '/css/font-awesome.min.css'); 

Below is the code that does work. 下面是起作用的代码。

  wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'); 

How do I go about linking or calling the Font Awesome stylesheet that is in my CSS folder? 如何链接或调用CSS文件夹中的Font Awesome样式表? I have added actions on my side, My only issue is getting the FA stylesheet to work manually. 我已经添加了一些操作,我唯一的问题是使FA样式表能够手动工作。

I think you forgot to add fonts directory.which contain fonts file used by the font-awesome.min.css file. 我认为您忘记添加字体目录。该目录包含font-awesome.min.css文件使用的字体文件。 在此处输入图片说明

I assume, that you are working on a child theme. 我认为您正在研究儿童主题。 You are calling the 'parent theme' directory when enqueuing the font-awesome. 使真棒字体入队时,您正在调用“父主题”目录。 Try to use wp_enqueue_style('font-awesome', get_stylesheet_directory_uri() . '/css/font-awesome.min.css'); 尝试使用wp_enqueue_style('font-awesome', get_stylesheet_directory_uri() . '/css/font-awesome.min.css');

More info https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri 更多信息https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

Also check the path to the CSS by puting it in the browser, ie http://www.example.com/wp-content/themes/mytheme/css/font-awesome.min.css 还要通过将CSS放在浏览器中来检查它的路径,即http://www.example.com/wp-content/themes/mytheme/css/font-awesome.min.css

Here's how I did it: 这是我的操作方式:

In the header.php file (or where-ever you keep your header code,) copy and paste this code: header.php文件中(或保存标题代码的任何位置)复制并粘贴以下代码:

<link rel="stylesheet" src="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

This is a whole lot better than fiddling with PHP. 这比摆弄PHP更好。 Another way is to install a Font Awesome plugin for WordPress, which does work. 另一种方法是为WordPress安装Font Awesome插件,该插件可以正常工作。 Just go to the Plugins area and search for "font awesome." 只需转到“插件”区域并搜索“真棒字体”即可。 Click the Easy FontAwesome plugin, install it, activate it and you're done! 单击Easy FontAwesome插件,安装并激活它,即可完成!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM