Jump to content
Search Community

Add gsap and scrolltrigger in wp function child theme

Davide Lakka test
Moderator Tag

Recommended Posts

Hello lads,
first of all I apologize for my little knowledge of php.
I added gspa to a project that I am carrying out, through the function.php of Hello Elementor child theme adding this simple code:

 

function wpb_adding_scripts(){
    
    wp_register_script( 'gsap', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js', array(), '1.0', true );
  
    wp_register_script( 'gsap-settings', get_stylesheet_directory_uri() .'/gsap.js', array('gsap'), '1.0', true );

    wp_enqueue_script('gsap'); // This is probably not needed since below we are enqueueing the gsap-settings file with has a dependency on the gsap script, so it should enqueue both
    wp_enqueue_script('gsap-settings');
}

add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );

 

and it works.

 

But the problem is that I can't add Scroll Trigger, and therefore all the functionality of this extra plugin via cdn in this function.

 

Can anyone help me?

 

Thanks, Davide

Link to comment
Share on other sites

Hi Davide,

 

Unfortunately I'm not well versed in Wordpress since I haven't used it in years, but as far as I know this should work:

function wpb_adding_scripts(){
    
    wp_register_script( 'gsap', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js', array(), '1.0', true );

    wp_register_script( 'ScrollTrigger', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/ScrollTrigger.min.js', array('gsap'), '1.0', true );
  
    wp_register_script( 'gsap-settings', get_stylesheet_directory_uri() .'/gsap.js', array('gsap', 'ScrollTrigger'), '1.0', true );

    wp_enqueue_script('gsap'); // This is probably not needed since below we are enqueueing the gsap-settings file with has a dependency on the gsap script, so it should enqueue both
    wp_enqueue_script('gsap-settings');
}

add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );

Hopefully another user with more experience in WordPress could chime in and shed some light into this.

 

Happy Tweening!!!

  • Like 2
Link to comment
Share on other sites

Hi @Davide Lakka,

 

You posted this same question in several other threads, I presume to get an answer as fast as possible. We always try to answer a question withing 24 hours or less, regardless if the user is a Club member or not. We value and respect every single user and the experience they have using GSAP and sorting their issues in the forums, every user is special to GreenSock and no question around here is considered a bad one. So be sure that as far as we can, we will try to help you as much as possible to solve this, as long as it is within our capacities to do so, with maximum respect and consideration.

 

On the note above I deleted the other posts you added in previous threads and we'll keep an eye in this one to help you solve this.

 

Also it might be worth taking a look at this thread on StackOverflow on the subject:

https://stackoverflow.com/questions/19263390/wordpress-loading-multiple-scripts-with-enqueue

 

Happy Tweening!!!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...