I connect scripts via function.php

function wp_add_scripts(){ wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', ['jquery']); wp_enqueue_script( 'loadport', get_template_directory_uri() . '/js/loadport.js', ['jquery']); wp_enqueue_script( 'materialize', get_template_directory_uri() . '/js/materialize.min.js', ['jquery'] ); wp_enqueue_script( 'myjs', get_template_directory_uri() . '/js/myjs.js', ['jquery'] ); // wp_enqueue_script( 'json', get_template_directory_uri() . '/js/portfolio.json', ['jquery']); }add_action('wp_enqueue_scripts', 'wp_add_scripts'); function jquery_init() { if (!is_admin()) { wp_enqueue_script('jquery'); }}add_action('wp_enqueue_scripts', 'jquery_init');' 

Scripts are connected like normal

 <script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.12.4'></script> 

But at the same time, an error is generated and the scripts do not work at all. I can not understand why. (immediately above the html code with the included scripts) enter image description here

    1 answer 1

    To you, the error clearly says "dude cannot read the event property of a non- existent object"
    This is most likely due to the fact that while the DOM script is running, the tree is not yet ready. Use the wp_enqueue_script function wp_enqueue_script to connect the script before the closing </body> more precisely, where the wp_footer() template tag is called.
    Here you can read more.

    This time.
    Secondly, the fonts were not connected, but the scripts work with them. Check this.

    • I did everything as it was written, I connected the fonts, everything that was not necessary was removed. But the error materialize.min.js: 7 Uncaught TypeError: Cannot read property 'event' of undefined remained. Everything is in the footer, after jquery. What else could be the problem? - Alexander Alekseev
    • I can’t say so to a vskidku, maybe the problem is in the connection sequence and script dependencies. - pepel_xD
    • Thanks for the answer. The problem was solved, do not believe how, I just perezalil file materialize.min.js in the project and everything was corrected, as I could not damage the mind, I did not touch it. - Alexander Alekseev