In this article, we’ll solve ReferenceError: _ is not defined in Shopify or WordPress. Sometimes when we using jQuery on the Shopify or WordPress theme that time we face this issue. There are several ways to fix it. We’ll show you the easiest way to fix it.

ReferenceError
ReferenceError: _ is not defined in Shopify or WordPress

Let’s get started:-

Fix Shopify

First, you need to know why this error. Your Shopify code needs Underscore.js or LoDash.js as a dependency.

  • You can get them here: underscorelodash.
  • Or, You can add this code to your theme.layout file.
     <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>  

Hopefully, your Shopify problem will be solved.

Fix WordPress

Now, let’s solve the WordPress problem

Your WordPress code also needs Underscore.js or LoDash.js as a dependency.

  • You can get them here: underscorelodash.
  • Or, You can add this code to your functions.php file.
     function bb_admin_scripts() {  
       wp_enqueue_script('underscore', 'cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js' );  
     }  
     add_action( 'admin_enqueue_scripts', 'bb_admin_scripts' );  
    

Hopefully, your WordPress problem will be solved.
If you have any questions feel free to ask anything in the comment section. We will get back to you.

About Jubayer Ahmad

Author, WordPress & Shopify expert

Leave a Comment

Your email address will not be published. Required fields are marked *