Directory of scripts not recognized

Asked

Viewed 42 times

0

I’m mounting a wordpress site on MAMP installed in windows and scripts . JS put so on 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 recognizes as "GET http://localhost:8888/protodesign/Assets/js/efeitos.js net:ERR_ABORTED"

On the other sites I did always worked out by putting the directory only from the Assets folder, but now it didn’t work.

what can be?

1 answer

0


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

That said, you are not using the correct methods to insert scripts in a Wordpress theme. Instead of putting tags in the template file, use wp_enqueue_script(), thus:

In the archive 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 archive footer.php:

<?php wp_footer(); ?>
</body>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.