Вопрос

Greeting WP Devs,

I am planning to transfer the script libraries in my function.php . In my function.php I registered AOS

function mypage() {
  if ( is_page( 'mypage' ) ) {

wp_register_script( 'aosjs', get_template_directory_uri() . 'js/aos.js', array( 'jquery' ), NULL, false );    
   wp_enqueue_script( 'aosjs' );

   wp_enqueue_script( 'jquery.min' );


add_action( 'wp_enqueue_scripts', 'testingarea');

Page Name : mypage

https://mysite/mypage/ - My script has cdn with AOS.init

 <script src="js/aos.js"></script>
  <script>
  AOS.init({
    easing: 'ease-in-out-sine'
  });
</script>

First Test- AOS is registered in functions.php aand in mypage I removed the cdn in the mypage Page and aos init is still there but the result is

enter image description here

..

PLease kindly give me suggestions on how to declare this properly.

Это было полезно?

Решение

The function get_template_directory_uri() returns the path without trailing slash.
So you need to write

wp_register_script( 'aosjs', get_template_directory_uri() . '/js/aos.js',...)

Note the slash before "js/aos.js".
What good for is this line, the script file should already be loaded:

<script src="js/aos.js"></script>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с wordpress.stackexchange
scroll top