如何在WordPress中为IE浏览器设置字体


How to set font face for internet explorer in WordPress?

我只在WordPress中为Internet Explorer设置字体

所有字体都位于子主题的根目录中。

这是仅 ie-中的代码.css

    @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { 
    @font-face {
    font-family: 'open_sansregular';
    src: url('opensans-regular-webfont.eot');
    src: url('opensans-regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('opensans-regular-webfont.woff2') format('woff2'),
         url('opensans-regular-webfont.woff') format('woff'),
         url('opensans-regular-webfont.ttf') format('truetype'),
         url('opensans-regular-webfont.svg#open_sansregular') format('svg');
    font-weight: normal;
    font-style: normal;
    }

    .text-highlight { border: 1px solid red; font-family:open_sansregular;  }
}

您知道在子主题的根目录中查找字体系列的正确地址是什么吗?

任何帮助,不胜感激。谢谢

我认为您没有相应地设置字体路径,请尝试此代码。

@font-face {
font-family: 'open_sansregular';
src: url('<?php echo get_stylesheet_directory_uri(); ?>/fonts/opensans-regular-webfont.eot');
src: url('<?php echo get_stylesheet_directory_uri(); ?>/fonts/opensans-regular-webfont.eot?#iefix') format('embedded-opentype'),
     url('<?php echo get_stylesheet_directory_uri(); ?>/fonts/opensans-regular-webfont.woff2') format('woff2'),
     url('<?php echo get_stylesheet_directory_uri(); ?>/fonts/opensans-regular-webfont.woff') format('woff'),
     url('<?php echo get_stylesheet_directory_uri(); ?>/fonts/opensans-regular-webfont.ttf') format('truetype'),
     url('<?php echo get_stylesheet_directory_uri(); ?>/fonts/opensans-regular-webfont.svg#open_sansregular') format('svg');
font-weight: normal;
font-style: normal;
}

我能够解决我的问题。

若要在 Internet Explorer 中启用字体,请为 IE 创建单独的 css。例:

<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(); ?>/ie-only.css" />

get_stylesheet_directory_uri() 将获取子主题的目录

现在仅在 ie-中.css

    @font-face {
    font-family: 'open_sansregular';
    src: url('fonts/opensans-regular-webfont.eot');
    src: url('fonts/opensans-regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('fonts/opensans-regular-webfont.woff2') format('woff2'),
         url('fonts/opensans-regular-webfont.woff') format('woff'),
         url('fonts/opensans-regular-webfont.ttf') format('truetype'),
         url('fonts/opensans-regular-webfont.svg#open_sansregular') format('svg');
    font-weight: normal;
    font-style: normal;
    }

上面声明的所有字体文件都应该在您正在使用的目录中可用。

谢谢。