Directory of scripts are not recognized

0

I'm setting up a wordpress site in MAMP installed on windows and the .JS scripts put it in the footer:

  <?php wp_footer(); ?>
  <script src="https://code.jquery.com/jquery-3.2.1.min.js"integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" 
          crossorigin="anonymous"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" 
           crossorigin="anonymous"></script>

    <script type="text/javascript" src="assets/js/efeitos.js">
    </script>
  </body>

Hence it does not work and on the console it recognizes as "GET link net :: ERR_ABORTED"

In the other sites that I have done, it always worked, putting the directory only from the assets folder, but now it did not work.

What can it be?

    
asked by anonymous 08.12.2017 / 20:05

1 answer

0

Assuming the assets folder exists within your theme, its path is probably wp-content/themes/nomedotema/assets/ . As it stands, PHP looks in /assets and finds nothing.

That said, you're not using the correct methods to insert scripts into a WordPress theme. Instead of putting the tags in the template file, use wp_enqueue_script() , like this:

In the file functions.php :

<?php
add_action( 'wp_enqueue_scripts', 'adiciona_scripts' );
function adiciona_scripts() {

    // jQuery já vem por padrão com o WP, então a chamada simples resolve,
    // você pode usar uma igual às outras abaixo se quiser mesmo buscar da CDN
    wp_enqueue_script( 'jquery' ); 

    // Scripts externos são chamados assim, veja o significado de cada atributo no link acima.
    wp_enqueue_script( 'popper', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js', array('jquery'), false, true );
    wp_enqueue_script( 'efeitos', get_template_directory_uri() . '/assets/js/efeitos.js', array('jquery'), false, true );
}

In the file footer.php :

<?php wp_footer(); ?>
</body>
    
09.12.2017 / 01:18