php WordPress谷歌字体集成
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WordPress谷歌字体集成相关的知识,希望对你有一定的参考价值。
<?php
/**
* Register custom fonts.
*/
function pccit_fonts_url() {
$fonts_url = '';
/*
* Translators: If there are characters in your language that are not
* supported by Droid Serif and Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
$primary = _x( 'on', 'Droid Serif font: on or off', 'pccit' );
$secondary = _x( 'on', ' Open Sans font: on or off', 'pccit' );
$font_families = array();
if( 'off' !== $primary){
$font_families[] = 'Droid Serif:400,700';
}
if( 'off' !== $secondary){
$font_families[] = 'Open Sans:400,700';
}
if ( in_array( 'on', array($primary, $secondary) ) ) {
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( $fonts_url );
}
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Seventeen 1.0
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array $urls URLs to print for resource hints.
*/
function pccit_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'pccit-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'pccit_resource_hints', 10, 2 );
wp_enqueue_style( 'pccit-fonts', pccit_fonts_url() );
以上是关于php WordPress谷歌字体集成的主要内容,如果未能解决你的问题,请参考以下文章
如何提高WordPress的加载速度
添加谷歌字体到Wordpress和管理标题
怎么解决Wordpress运行慢的问题
很好用的谷歌字体以及Gravatar头像一键替换WordPress插件----WP Acceleration for China 插件
谷歌浏览器第一次访问时不会显示字体(css3、wordpress)。 (仅在刷新时)
Wordpress主题文件夹中的functions.php作用说明