HEy, in meinem Theme wird folgende Funktion für die Google Fonts verwendet:
/**
* Enqueue google fonts.
*
* @access public
* @return null
*/
public function enqueue_fonts() {
// Check if we need to exit early.
if ( empty( self::$fields ) || ! is_array( self::$fields ) ) {
return;
}
foreach ( self::$fields as $field ) {
// Process typography fields.
if ( isset( $field['type'] ) && in_array( $field['type'], array(
'typography',
'kirki_typography',
), true ) ) {
// Check if we've got everything we need.
if ( ! isset( $field['kirki_config'] ) || ! isset( $field['settings'] ) ) {
continue;
}
$value = self::get_option( $field['kirki_config'], $field['settings'] );
if ( isset( $value['font-family'] ) ) {
$url = '//fonts.googleapis.com/css?family=' . str_replace( ' ', '+', $value['font-family'] );
$value['variant'] = ( isset( $value['variant'] ) ) ? $value['variant'] : '';
$url .= ( empty( $value['variant'] ) ) ? '' : ':' . $value['variant'];
$value['subset'] = ( isset( $value['subset'] ) ) ? $value['subset'] : '';
if ( ! empty( $value['subset'] ) ) {
$value['subset'] = ( is_array( $value['subset'] ) ) ? implode( ',', $value['subsets'] ) : $value['subset'];
$url .= '&subset=' . $value['subset'];
}
$key = md5( $value['font-family'] . $value['variant'] . $value['subset'] );
// Check that the URL is valid. we're going to use transients to make this faster.
$url_is_valid = get_transient( $key );
// If transient does not exist.
if ( false === $url_is_valid ) {
$response = wp_remote_get( 'https:' . $url );
if ( ! is_array( $response ) ) {
// The url was not properly formatted,
// cache for 12 hours and continue to the next field.
set_transient( $key, null, 12 * HOUR_IN_SECONDS );
continue;
}
// Check the response headers.
if ( isset( $response['response'] ) && isset( $response['response']['code'] ) ) {
if ( 200 == $response['response']['code'] ) {
// URL was ok. Set transient to true and cache for a week.
set_transient( $key, true, 7 * 24 * HOUR_IN_SECONDS );
$url_is_valid = true;
}
}
}
// If the font-link is valid, enqueue it.
if ( $url_is_valid ) {
wp_enqueue_style( $key, $url, null, null );
}
}
}
}
}
Alles anzeigen
Kann ich diese irgendwie in meiner functions.php deaktivieren? Und suche ich hier nicht an der richtigen Stelle?
Hier habe ich noch was gefunden:
public function __construct() {
// If Kirki exists then there's no reason to proceed.
if ( class_exists( 'Kirki' ) ) {
return;
}
// Add our CSS.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ), 20 );
// Add google fonts.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_fonts' ) );
}
Alles anzeigen
LG