wordpress/php-fpm/wordpress_files/plugins/disable-remove-google-fonts/disable-remove-google-fonts.php
2020-05-22 01:40:23 +00:00

56 lines
1.4 KiB
PHP

<?php
/**
* Plugin Name: Disable/Remove Google Fonts
* Plugin URI: https://wordpress.org/plugins/disable-remove-google-fonts/
* Description: Improve frontend performance by disabling Google Fonts.
* Author: Fonts Plugin
* Author URI: https://fontsplugin.com
* Version: 1.1.3
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*
* @package disable-remove-google-fonts
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Dequeue Google Fonts based on URL.
*/
function drgf_dequeueu_fonts() {
global $wp_styles;
if ( ! ( $wp_styles instanceof WP_Styles ) ) {
return;
}
$allowed = apply_filters(
'drgf_exceptions',
[ 'olympus-google-fonts' ]
);
foreach ( $wp_styles->registered as $style ) {
$handle = $style->handle;
$src = $style->src;
$gfonts = strpos( $src, 'fonts.googleapis' );
if ( false !== $gfonts ) {
if ( ! array_key_exists( $handle, array_flip( $allowed ) ) ) {
wp_dequeue_style( $handle );
}
}
}
// Dequeue Google Fonts loaded by Revolution Slider.
remove_action( 'wp_footer', array( 'RevSliderFront', 'load_google_fonts' ) );
}
add_action( 'wp_enqueue_scripts', 'drgf_dequeueu_fonts', 9999 );
add_action( 'wp_print_styles', 'drgf_dequeueu_fonts', 9999 );
/**
* Dequeue Google Fonts loaded by Elementor.
*/
add_filter( 'elementor/frontend/print_google_fonts', '__return_false' );