最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp enqueue script - Unable to declare AOS library in functions

programmeradmin0浏览0评论

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

..

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

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

..

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

Share Improve this question asked Feb 13, 2019 at 10:03 Sasuke ScendSasuke Scend 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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>
发布评论

评论列表(0)

  1. 暂无评论