0

I have an HTML site, that I need to implement into Wordpress.

Now I have problems to get the functions to start.

I have the Avada theme activated and paste the inline js code with the "code block" element into the site. The inline js is wrapped into $(document).ready(function () { }); and calling an object with object = new Object(options, options);. Until here everything works fine, but then I get an error in the additionally js file.

The structure in the additionally file is as follows:

class 1 {
}
class 2 {
}
class Object {
  constructor {}
  function {}
  function {}
  and so on
}

And in that file I'm getting an Uncaught TypeError: Cannot read property 'extend' of undefined.

This is the row:

this.options = $.extend({}, defaultOptions, options);

I'm pretty sure it's because of the jQuery.

The file is added with the following function

wp_register_script('custom-script', get_stylesheet_directory_uri() . '/script.js', array('jquery'), '1.11.2', true);

I don't know if it's better to wrap everything with jQuery and how to do it or to replace the jQuery things with plain javascript?

Howard E
  • 5,454
  • 3
  • 15
  • 24
Sega
  • 47
  • 6
  • Use `jQuery(...` instead of `$(...` in wordpress – freedomn-m Oct 23 '20 at 09:04
  • Does this answer your question? [TypeError: $ is not a function when calling jQuery function](https://stackoverflow.com/questions/12343714/typeerror-is-not-a-function-when-calling-jquery-function) – freedomn-m Oct 23 '20 at 09:05
  • This might be better: https://stackoverflow.com/a/7975203/2181514 or maybe https://stackoverflow.com/a/12025482/2181514 – freedomn-m Oct 23 '20 at 09:06
  • @freedomn-m I already tried to wrap the whole js file with all the classes into a function like in the example. The problem then is that I get the the error that the object isn't defined. Also when I try just to wrap these specific lines into the function, I'm getting different errors and in the end it's still not work. – Sega Oct 23 '20 at 09:17

0 Answers0