Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jerryB

Enqueue GSAP into WordPress theme

Recommended Posts

Hi,

I downloaded the member source files and have them in my theme's directory; I'm trying to enqueue to GSAP and ScrollTrigger, but not sure of the exact coding or which files in the folder I need to connect to; this is what I have, but it's not working ... thanks

<?php
function add_gsap_scripts() {

    wp_enqueue_script ( 'gsap-js' , get_stylesheet_directory_uri() . '/lib/gsap/minified/gsap.min.js', array( 'jquery' ), '1', true );
    wp_enqueue_style ( 'gsap-ScrollTrigger' , get_stylesheet_directory_uri() . '/lib/gsap/minified/ScrollTrigger.min.js', '', '1', 'all' );

    wp_enqueue_script( 'gsap-custom', get_template_directory_uri() . '/js/custom-gsap-scripts.js', array(), false, true );
}
add_action( 'wp_enqueue_scripts', 'add_gsap_scripts' );
?>

Link to comment
Share on other sites

Hi there JerryB,


I'm afraid my wordpress knowledge is a little shaky but this thread may be of use -
 



 

  • Like 1
Link to comment
Share on other sites

Hi Jerry!

 

I'm not familiar with WordPress. Maybe this thread will be of help? If not, try searching the forums for enqueue as it's been brought up many times before.

 

 

 

  • Like 1
Link to comment
Share on other sites

Thanks, yeah, I did see those, but they are using the CDN--I can get that to work--but I need to enqueue to the local file. Was hoping to find an example of that from a user. Thanks

Link to comment
Share on other sites

It doesn't look they are using CDNs for every file. Here's another one.

 

Or maybe try asking how to load scripts through a WordPress support channel.

 

Link to comment
Share on other sites

Ah, thanks, that looks closer; I'll play with that config

  • Like 1
Link to comment
Share on other sites

Hey Jerry,

 

It looks like you enqueue gsap from a child theme and then enqueue your custom-gsap-scripts.js from the parent theme.  If all the scripts are in the child theme you need to use:  get_stylesheet_directory_uri(). 

 

If you do not have a child theme and are modifying or building a custom theme use: get_template_directory_uri().

 

Check the console and make sure they are loading and you are not getting 404 errors.

  • Like 1
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.
×