skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  2. The two scripts are also added without contact-form-7. But I can deregister both without errors with:

    wp_deregister_script('wp-polyfill');
    wp_deregister_script('regenerator-runtime');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search