How to fix $.browser undefined error in WordPress with jQuery Migrate

  • Home
  • How to fix $.browser undefined error in WordPress with jQuery Migrate

$.browser function has been deprecated from the latest jQuery version. It had the flags $.browser.webkit, $.browser.safari, $.browser.opera, $.browser.msie and $.browser.mozilla to detect respective browsers in previous versions. But now, if your site has code with these flags and your theme has the latest version of jQuery, then it will throw an error message sayings “undefined”. But do not worry, you can fix it.

From WordPress version 5.5, “jquery-migrate” library has been removed from WordPress core. Hence, you will get an error if your theme or any other plugins are trying to access any jQuery features that are deprecated. You can also install a plugin called Enable jQuery Migrate Helper, to include the jquery-migrate library in the latest version of WordPress.

How to fix $.browser error:

Normally this issue occurs in an older version of themes that are not updated. You have to enqueue the jquery-migrate library in your theme to fix the issue.

if ( !function_exists( 'wptips_add_juery_migrate' ) ) {
  /**
   * Add jQuery Migrate script in front end.
   *
   */
  function wptips_add_juery_migrate() {
    wp_enqueue_script( 'jquery-migrate' );
  }
}
add_action( 'wp_head', 'wptips_add_juery_migrate' );

You can check your theme for jquery script enqueue or any other script with jquery as a dependency and make sure that you add an additional dependency of jquery-migrate to fix the issue.

How to fix errors in the admin section only :

// add jquery migrate only to the admin section
function wptips_add_jquery_migrate() {  
        wp_enqueue_script('jquery-migrate');  
}  
add_action('admin_enqueue_scripts', 'wptips_add_jquery_migrate'); 

Note: You have to add the code in the functions.php file of your active theme for it to work.


If you still have any questions, please ask me in the comment section. I will be glad to help you out.

7 Comments

  1. Luke

    This solved my problem, great post!

    Reply
  2. CyBall

    I don’t know where to put those code snippets.
    Do I need both snippets or only the first.

    Reply
    • Murali Kumar

      You can use only the first snippet. Insert the snippet in functions.php file of your currently active theme.

      Feel free to let me know, if you still have any questions. 🙂

      Reply
      • Max Luna

        Is it posible to use jquery1.xxx in the whole site but jquery1.yyy in two specific pages?

        Reply
  3. Will

    Hello Murai Kumar, I’m trying to put the code “wp_enqueue_script(‘jquery-migrate’); ” in the “file wp-includer/funcitions.php” but it does’nt work for me. I’m using a flexifrid to show information in a table. Now I upgraded WordPress and CodeIgniter. Now WordPress version 5.6.1. I have this in the browser console:

    JQMIGRATE: Migrate is installed, version 3.3.2
    Uncaught TypeError: $.browser is undefined
    addFlex http://educa/ci_portal_uho/assets/flexigrid/flexigrid.pack.js:874
    flexigrid http://educa/ci_portal_uho/assets/flexigrid/flexigrid.pack.js:1438
    jQuery 2
    flexigrid http://educa/ci_portal_uho/assets/flexigrid/flexigrid.pack.js:1425
    http://educa/ci_portal_uho/index.php/recursos_pre/recursos_pre_site:153
    jQuery 10
    http://educa/ci_portal_uho/index.php/recursos_pre/recursos_pre_site:150
    jQuery 13
    flexigrid.pack.js:874:8

    ​

    Reply
    • somali

      You need to go to the folder of your active theme and then insert the code in functions.php as described. That worked for me.

      Reply

Leave a comment