Views 678
How to Connect GSAP to your WordPress Site With and without plugin

How to Connect GSAP to your WordPress Site With and without plugin – The GreenSock Animation Platform (GSAP) is a powerful JavaScript library that makes complex animations simple and performance-efficient. Whether you want to animate menus, scroll-based interactions, or eye-catching transitions, GSAP is an excellent tool for modern web design. In this article, we’ll walk you through connecting GSAP to your WordPress site and adding smooth animations.
How to connect GSAP to wordpress website using plugin

To add animation for your website via plugin, you need to use motion.page plugin, visit here
- Download the plugin
- Install the plugin by uploading the zip file to Plugins > Add New
- You will see the new “Motion.page” link at the bottom of the WP sidebar, which launches the builder
- Launch the builder, and add your license key on the welcome screen to activate it.
How to connect GSAP to WordPress website Without using plugin
Step 1: Download GSAP
Before you add GSAP to your WordPress site, you need the GSAP library. There are two main ways to get GSAP:
Option 1: Use GSAP via CDN
For a quick setup, you can use a CDN link. This eliminates the need to download any files and allows GSAP to load from a trusted server.
GSAP CDN link:
htmlCopy code<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.0/gsap.min.js"></script>
Option 2: Download GSAP Manually
You can download GSAP from the official website:
- Visit the GSAP download page.
- Download the library and extract the contents to your local system.
- Upload the
gsap.min.js
file to your WordPress theme or child theme, typically inside theassets/js/
directory.
Step 2: Enqueue GSAP in WordPress
In WordPress, the proper way to load external scripts is through the functions.php
file using the wp_enqueue_script()
function. This ensures the script is loaded correctly and without conflicts.
To add GSAP, follow these steps:
- Open your theme’s
functions.php
file (or your child theme if you’re using one). - Add the following code to enqueue GSAP:
For CDN:
phpCopy codefunction enqueue_gsap() {
wp_enqueue_script(
'gsap-js',
'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.0/gsap.min.js',
array(),
null,
true // Load script in the footer
);
}
add_action('wp_enqueue_scripts', 'enqueue_gsap');
For Local File:
If you uploaded GSAP to your theme’s assets/js/
directory, you can enqueue it like this:
phpCopy codefunction enqueue_gsap_local() {
wp_enqueue_script(
'gsap-js',
get_template_directory_uri() . '/assets/js/gsap.min.js',
array(),
null,
true // Load script in the footer
);
}
add_action('wp_enqueue_scripts', 'enqueue_gsap_local');
Step 3: Add Custom Animations
Now that GSAP is connected to your WordPress site, you can start adding custom animations. You’ll write JavaScript to define the animations. You can either include your animation script directly in a template file or create a separate .js
file for organization.
Example Animation:
To animate an element with the class .my-element
using GSAP, add this JavaScript either inside a separate file (e.g., custom-animations.js
) or directly into your WordPress theme:
jsCopy codegsap.to('.my-element', {
duration: 2,
x: 100,
opacity: 0.5
});
If you use a separate file (recommended), enqueue the file in your functions.php
:
phpCopy codefunction enqueue_custom_animations() {
wp_enqueue_script(
'custom-animations',
get_template_directory_uri() . '/assets/js/custom-animations.js',
array('gsap-js'), // GSAP as a dependency
null,
true
);
}
add_action('wp_enqueue_scripts', 'enqueue_custom_animations');
Step 4: Apply Animations to Your Content
Once you have GSAP enqueued and your custom animation script in place, apply animations to any elements on your WordPress site. For example:
- Add a target class to an element in your post/page:
htmlCopy code<div class="my-element">Animate me with GSAP!</div>
- GSAP will now animate that element based on the script you created.
Step 5: Test and Optimize
It’s crucial to test the animations across different browsers and devices. GSAP is optimized for performance, but ensure your animations run smoothly, especially on mobile. GSAP offers performance tools such as gsap.ticker()
to monitor frame rates.
Conclusion
Integrating GSAP into your WordPress site is simple and allows you to create stunning animations with ease. By enqueuing the GSAP library and writing custom scripts, you can bring dynamic animations to your website. Now that you know how to connect GSAP to WordPress, you’re ready to create interactive experiences that engage your users.
Bestway:-
Load gsap files to your child theme

Enqueue scripts like these
function enqueue_global_styles_and_scripts() {
// Enqueue global stylesheet from child theme
$stylesheet_uri = get_stylesheet_directory_uri() . '/style.css';
$stylesheet_version = filemtime( get_stylesheet_directory() . '/style.css' );
wp_enqueue_style( 'global_styles', $stylesheet_uri, array(), $stylesheet_version );
// Enqueue GSAP from child theme
$gsap_uri = get_stylesheet_directory_uri() . '/gsap.min.js';
$gsap_version = filemtime( get_stylesheet_directory() . '/gsap.min.js' );
wp_enqueue_script( 'gsap_js', $gsap_uri, array(), $gsap_version, true );
// Enqueue ScrollTrigger from child theme
$scrolltrigger_uri = get_stylesheet_directory_uri() . '/ScrollTrigger.min.js';
$scrolltrigger_version = filemtime( get_stylesheet_directory() . '/ScrollTrigger.min.js' );
wp_enqueue_script( 'scrolltrigger_js', $scrolltrigger_uri, array('gsap_js'), $scrolltrigger_version, true );
// Enqueue imagesLoaded from child theme
$imagesloaded_uri = get_stylesheet_directory_uri() . '/imagesloaded.pkgd.min.js';
$imagesloaded_version = filemtime( get_stylesheet_directory() . '/imagesloaded.pkgd.min.js' );
wp_enqueue_script( 'imagesloaded_js', $imagesloaded_uri, array(), $imagesloaded_version, true );
// Enqueue custom JavaScript file from child theme
$script_uri = get_stylesheet_directory_uri() . '/scripts.js';
$script_version = filemtime( get_stylesheet_directory() . '/scripts.js' );
wp_enqueue_script( 'custom_js', $script_uri, array(), $script_version, true );
}
add_action( 'wp_enqueue_scripts', 'enqueue_global_styles_and_scripts' );
Now ready to use gsap
jsCopy codegsap.to('.my-element', {
duration: 2,
x: 100,
opacity: 0.5
});
You can get more Tips here HOW TO articles here