WordPress disable "regenerator-runtime-js" and "wp-polyfill-js"

Viewed 1122

These two srcripts are added on every footer of my WordPress pages. Is it possible to remove them via functions.php?

1 Answers

The following code in your functions.php should remove wp-polyfill and regenerator-runtime:

function deregister_polyfill(){

  wp_deregister_script( 'wp-polyfill' );
  wp_deregister_script( 'regenerator-runtime' );

}
add_action( 'wp_enqueue_scripts', 'deregister_polyfill');

See also: wp_deregister_script

Edit: After further investigation on the problem, I found that these styles are included by the Contact Form 7 plugin. My solution to the problem was to write a Must Use Plugin so that the Contact Form 7 plugin is only included when you are in the contact form.

For this purpose I have created the following file:

wp-content/mu-plugins/tk-mu-plugins.php

which is filled as follows:

<?php
/*
Plugin Name: TK-MU-Plugin
Description: 
Author: Thomas Krakow
Version: 1.0
Author URI: https://thomas-krakow.de
*/

$fRequestURI = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
if( false === strpos( $fRequestURI, '/wp-admin/' ) ){           
    add_filter( 'option_active_plugins', 'tk_activate_plugins' );
}

function tk_activate_plugins( $plugins ){
        
    global $fRequestURI;
    $is_contact_page = strpos( $fRequestURI, '/contact/' );
    
    $k = array_search( "contact-form-7/wp-contact-form-7.php", $plugins );
    
    if( false !== $k && false === $is_contact_page ){
        unset( $plugins[$k] );
    }
    
    return $plugins;
}

My Code at GitHub Gist: tk-mu-plugin.php

Explanation in German on my blog: CSS und Javascript nur bei Bedarf auf WordPress-Seiten einfügen

Related