【问题标题】:importing custom font in Wordpress theme in function.php在 function.php 中的 Wordpress 主题中导入自定义字体
【发布时间】:2017-01-10 05:55:13
【问题描述】:

我想在我的自定义 Wordpress 中使用自定义字体 (@fontface)。我在我的functions.php中引入了谷歌字体,就像这样

wp_enqueue_style( 'Lato', '//fonts.googleapis.com/css?family=Lato:300,400,700,900', array() );

但想使用我的字体文件夹中的字体(主题名称/字体/...)我不知道该怎么做,我通常会使用 @fontface... 但不确定它如何与 Wordpresss

编辑我想把它放在我的functions.php文件中

【问题讨论】:

    标签: css wordpress fonts


    【解决方案1】:

    像这样使用 css 导入它:

    <link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:300,400,700,900'" />
    

    然后就可以使用了:

    font-family: 'Lato', sans-serif;
    

    【讨论】:

    • 我想把它放在我的functions.php中那行还能用吗?
    • 将上面的代码包装在一个函数中,这样调用它: add_action( 'wp_enqueue_scripts', 'functionname' );
    【解决方案2】:
    @font-face {
    font-family: 'give-any-name-to-font-famaly';
    src: url('font-name.eot');
    src: url('font-name.eot?#iefix') format('embedded-opentype'),
    url('font-name.woff') format('woff'),
    url('font-name.ttf') format('truetype'),
    url('font-name.svg#font-name') format('svg');
    font-weight: normal;
    font-style: normal;
    }
    

    在css中使用字体:

    font-family: 'give-any-name-to-font-famaly';
    

    【讨论】:

      猜你喜欢
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 2020-01-28
      • 1970-01-01
      • 2012-01-15
      • 2017-01-02
      相关资源
      最近更新 更多