Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wp_default_scripts', function( $scripts ) {
- if ( ! empty( $scripts->registered['jquery'] ) ) {
- $scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, array( 'jquery-migrate' ) );
- }
- } );
- // silencer script
- function jquery_migrate_silencer() {
- // create function copy
- $silencer = '<script>window.console.logger = window.console.log; ';
- // modify original function to filter and use function copy
- $silencer .= 'window.console.log = function(tolog) {';
- // bug out if empty to prevent error
- $silencer .= 'if (tolog == null) {return;} ';
- // filter messages containing string
- $silencer .= 'if (tolog.indexOf("Migrate is installed") == -1) {';
- $silencer .= 'console.logger(tolog);} ';
- $silencer .= '}</script>';
- return $silencer;
- }
- // for the frontend, use script_loader_tag filter
- add_filter('script_loader_tag','jquery_migrate_load_silencer', 10, 2);
- function jquery_migrate_load_silencer($tag, $handle) {
- if ($handle == 'jquery-migrate') {
- $silencer = jquery_migrate_silencer();
- // prepend to jquery migrate loading
- $tag = $silencer.$tag;
- }
- return $tag;
- }
- // for the admin, hook to admin_print_scripts
- add_action('admin_print_scripts','jquery_migrate_echo_silencer');
- function jquery_migrate_echo_silencer() {echo jquery_migrate_silencer();}
- // Set to true to prevent console output; migrateWarnings still maintained
- // jQuery.migrateMute = false;
- add_action( 'wp_enqueue_scripts', function()
- {
- wp_add_inline_script(
- 'jquery-migrate', 'jQuery.migrateMute = true;',
- 'before'
- );
- } );
- // Show a message on the console so devs know we're active
- if ( window.console && window.console.log ) {
- window.console.log( "JQMIGRATE: Migrate is installed" +
- ( jQuery.migrateMute ? "" : " with logging active" ) +
- ", version " + jQuery.migrateVersion );
- }
- console.clear();
- <?php
- /**
- * Disable jQuery Migrate in WordPress.
- *
- * @author Guy Dumais.
- * @link https://en.guydumais.digital/disable-jquery-migrate-in-wordpress/
- */
- add_filter( 'wp_default_scripts', $af = static function( &$scripts) {
- if(!is_admin()) {
- $scripts->remove( 'jquery');
- $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' );
- }
- }, PHP_INT_MAX );
- unset( $af );
Add Comment
Please, Sign In to add comment