在Wordpress站点中使用托管在AWS S3上的自定义字体


Using custom fonts hosted on AWS S3 in a Wordpress site

我将typography.com中的字体转移到生产环境中,并将其上传到我的AWS S3 Bucket中,以便在我的Wordpress站点上使用。我已经按照typography.com的要求做了所有的事情,但是字体仍然没有显示出来。有人经历过这种情况吗能给我指路吗?我在主题的style.css中添加了@import语句到typography.com给我的url。我还在functions.php中有一个wp_enqueue函数,我已将其上传到S3服务器。

 add_action( 'wp_head', 'my_fonts' );
function my_fonts(){ ?>
<link rel="stylesheet" type="text/css" href="//cloud.typography.com/7783912/761788/css/fonts.css">
<?php
}

字体仍未显示。我做错了什么?

包含样式表的正确方法是使用wp_enqueue_style。使用此函数还允许您将此字体声明为其他样式表的依赖项。您还应该使用'wp_enqueue_scripts'钩子,而不是'wp_head':

/**
 * Proper way to enqueue scripts and styles
 */
function theme_name_scripts() {
    wp_enqueue_style( 'typography', '//cloud.typography.com/7783912/761788/css/fonts.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

如果此时您仍然有问题,请确保您具有从Typography云服务器获取此文件的适当权限。