我有一个这样的PHP文件:
final class FLBuilderFonts {
/**
* An array of fonts / weights.
* @var array
*/
static private $fonts = array();
static private $enqueued_google_fonts_done = false;
/**
* @since 1.9.5
* @return void
*/
static public function init() {
add_filter( 'the_content', __CLASS__ . '::combine_google_fonts', 11 );
add_action( 'wp_enqueue_scripts', __CLASS__ . '::combine_google_fonts', 10000 );
add_action( 'wp_enqueue_scripts', __CLASS__ . '::enqueue_google_fonts', 9999 );
add_filter( 'wp_resource_hints', __CLASS__ . '::resource_hints', 10, 2 );
add_action( 'wp_head', array( __CLASS__, 'preload' ), 5 );
}
static public function preload() {
$fa_version = FLBuilder::get_fa5_version();
$icons = array(
'foundation-icons' => array(
'https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.woff',
),
'font-awesome-5' => array(
FL_BUILDER_URL . 'fonts/fontawesome/' . $fa_version . '/webfonts/fa-brands-400.woff2',
FL_BUILDER_URL . 'fonts/fontawesome/' . $fa_version . '/webfonts/fa-solid-900.woff2',
FL_BUILDER_URL . 'fonts/fontawesome/' . $fa_version . '/webfonts/fa-regular-400.woff2',
),
);
// if using pro cdn do not preload as we have no idea what the url will be.
if ( get_option( '_fl_builder_enable_fa_pro', false ) || apply_filters( 'fl_enable_fa5_pro', false ) ) {
unset( $icons['font-awesome-5'] );
}
foreach ( $icons as $key => $preloads ) {
if ( wp_style_is( $key, 'enqueued' ) ) {
foreach ( $preloads as $url ) {
printf( '<link rel="preload" href="%s" as="font" type="font/woff2" crossorigin="anonymous">' . "n", $url );
}
}
}
}
如何通过命令禁用该行?
add_action( 'wp_head', array( __CLASS__, 'preload' ), 5 );
我试过在主题的functions.php文件中插入各种remove_action命令,但它不起作用。希望有人能帮助我。
非常感谢!
试试下面的代码。代码将放在您的活动主题函数。php文件中。
global $FLBuilderFonts;
remove_action( 'wp_head', array( $FLBuilderFonts, 'preload' ) );
或
add_action( 'wp_head', 'remove_preload_action', 10, 1 );
function remove_preload_action(){
$FLBuilderFonts = new FLBuilderFonts();
remove_action( 'wp_head', array( $FLBuilderFonts, 'preload' ) );
}
如果仍然不工作,尝试更改操作的优先级。