3.3 Different ways to add GSAP to a WordPress site
When working with WordPress and BricksBuilder, there is no single correct way to add GSAP. In practice, there are several valid methods, and each has different strengths, weaknesses, and ideal use cases. Choosing the right setup early will save you a lot of frustration later ⚙️
The main goal is always the same:
- Load GSAP core correctly
- Load any GSAP plugins you need
- Load your own animation code
- Make sure the loading order is reliable
- Keep the setup maintainable as your site grows
A useful mental model is:
$$
\text{Animation setup} = \text{library files} + \text{your custom code} + \text{correct load order}
$$
If even one of these parts is missing, your animations may fail, partially work, or behave unpredictably.
The main ways to add GSAP in WordPress
There are five common approaches you should know:
- Add GSAP via a CDN
- Add GSAP by hosting the files locally
- Add GSAP through your theme or child theme
- Add GSAP directly inside BricksBuilder custom code areas
- Add GSAP using a plugin or code management tool
You do not need to use all of them. Usually, you will pick one main strategy and stay consistent.
1. Adding GSAP via CDN
A CDN (Content Delivery Network) is one of the fastest and easiest ways to start. Instead of storing GSAP files in your WordPress installation, you load them from an external URL.
How it works
You include a script tag that points to the GSAP file hosted elsewhere, for example:
<script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
If you need a plugin such as ScrollTrigger, you also load that after GSAP core:
<script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/ScrollTrigger.min.js"></script>
Then your own animation script comes after both:
<script>
document.addEventListener("DOMContentLoaded", function() {
gsap.to(".box", {
y: -50,
duration: 1
});
});
</script>
Why beginners like this method
- It is quick to set up
- You do not need to upload files manually
- You can test GSAP in just a few minutes
- It works well for learning and experimentation
Advantages
-
Very easy to start
You can add one or two script tags and immediately verify that GSAP is working.
-
No file management
You do not need to download library files or place them in theme folders.
-
Good for testing
If you want to create a simple “GSAP is working” test animation, CDN is often the fastest route.
-
Convenient in Bricks
You can place the CDN script in site-wide code areas and begin quickly.
Disadvantages
-
External dependency
Your site relies on another server to deliver the script.
-
Less control
If you want strict control over versions, caching, or file location, local hosting can be better.
-
Can become messy
If you scatter CDN snippets across multiple places in WordPress, it becomes harder to manage.
-
Potential policy issues
Some projects or clients prefer fewer external dependencies for privacy, compliance, or performance reasons.
Best use cases
- Learning GSAP for the first time
- Building a quick prototype
- Testing whether GSAP works in your site
- Smaller projects with simple needs
Important loading order
If using CDN, always load in this order:
- GSAP core
- Plugins
- Your custom script
For example:
<script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/ScrollTrigger.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
gsap.registerPlugin(ScrollTrigger);
gsap.from(".hero-title", {
y: 60,
opacity: 0,
duration: 1
});
});
</script>
2. Hosting GSAP locally on your WordPress site
This means you download the GSAP files and place them in your own website files, usually inside your theme or child theme.
How it works
Instead of linking to an external CDN URL, you load a file from your own site, such as:
<script src="/wp-content/themes/your-child-theme/assets/js/gsap.min.js"></script>
You might structure your files like this:
your-child-theme/
assets/
js/
gsap.min.js
ScrollTrigger.min.js
custom-animations.js
Why this method matters
Local hosting gives you more control. Many developers prefer this setup for professional projects because it is easier to manage consistently over time.
Advantages
-
Full control over files
You decide which version of GSAP is loaded and when it gets updated.
-
No reliance on third-party delivery
Everything comes from your own site.
-
Cleaner long-term setup
Especially useful if your site grows and uses many custom scripts.
-
Better for structured development
You can organize scripts, versions, and custom code more cleanly.
Disadvantages
-
Slightly more setup work
You need to upload files and reference them correctly.
-
Requires basic file organization
You should understand where theme files live and how WordPress loads assets.
-
Version updates are manual
If you want a newer GSAP version, you must replace the files yourself.
Best use cases
- Production websites
- Projects that need better maintainability
- Client sites where you want stable, controlled asset loading
- More advanced setups with multiple custom scripts
Recommended approach
If you are serious about using GSAP regularly, this is one of the best long-term methods ✅
3. Adding GSAP through a theme or child theme
This is not really separate from local hosting—it is more the WordPress-native way to do it properly.
Instead of just pasting script tags somewhere, you use WordPress functions to enqueue scripts.
Why enqueuing matters
In WordPress, scripts should ideally be added using wp_enqueue_script(). This gives WordPress better control over:
- Dependencies
- Loading order
- Footer loading
- Versioning
- Conflict prevention
This is the professional way to load scripts.
Example using functions.php
Here is a clean example for a child theme:
function mytheme_enqueue_gsap_scripts() {
wp_enqueue_script(
'gsap',
get_stylesheet_directory_uri() . '/assets/js/gsap.min.js',
array(),
'3.12.5',
true
);
wp_enqueue_script(
'gsap-scrolltrigger',
get_stylesheet_directory_uri() . '/assets/js/ScrollTrigger.min.js',
array('gsap'),
'3.12.5',
true
);
wp_enqueue_script(
'custom-gsap-animations',
get_stylesheet_directory_uri() . '/assets/js/custom-animations.js',
array('gsap', 'gsap-scrolltrigger'),
'1.0.0',
true
);
}
add_action('wp_enqueue_scripts', 'mytheme_enqueue_gsap_scripts');
Why this is powerful
Notice the dependency arrays:
array()for GSAP corearray('gsap')for ScrollTriggerarray('gsap', 'gsap-scrolltrigger')for your own script
This tells WordPress:
- load GSAP first
- then load ScrollTrigger
- then load your custom animation file
So WordPress handles the order for you.
Advantages
- Most professional WordPress method
- Reliable dependency handling
- Cleaner than random script tags
- Scales well on larger projects
- Works well with child themes
Disadvantages
- Requires access to theme files
- Needs some PHP comfort
- Slightly harder for complete beginners
Best use cases
- Serious WordPress projects
- Child-theme-based workflows
- Sites with reusable custom functionality
- Cases where you want clean script architecture
Important note for Bricks users
If you use BricksBuilder, this method is still excellent. Bricks does not replace WordPress script best practices. Bricks is your builder, but WordPress is still the underlying system.
So if you are comfortable using a child theme, this is often one of the best foundations for GSAP.
4. Adding GSAP directly in BricksBuilder custom code
BricksBuilder gives you several places to add code, which makes it attractive for people who want a simpler workflow.
This can include:
- Page settings custom code
- Template-level custom code
- Site-wide custom code
- Header or footer script areas
- Code elements inside the builder
This method is often the most approachable for non-developers because it avoids editing theme files.
Typical workflow
You might:
- Add the GSAP CDN script globally
- Add plugin scripts globally
- Add your custom animation JS in Bricks custom code or in a code element
For example:
<script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/ScrollTrigger.min.js"></script>
Then later, in a custom code area:
<script>
document.addEventListener("DOMContentLoaded", function() {
gsap.registerPlugin(ScrollTrigger);
gsap.from(".card", {
opacity: 0,
y: 40,
duration: 0.8,
stagger: 0.15
});
});
</script>
Advantages
-
Very convenient
You can manage code from inside the builder interface.
-
No need to edit theme files
This lowers the technical barrier significantly.
-
Great for page-specific animations
If an animation is only used on one page, this can be very practical.
-
Fast iteration
You can tweak and test quickly while designing the page.
Disadvantages
-
Can become disorganized
If you place scripts in many different templates and pages, it becomes hard to track them.
-
Dependency management is manual
You need to make sure GSAP is loaded before your custom script.
-
Less ideal for large codebases
As your project grows, a theme-based script setup can be cleaner.
-
Risk of duplication
You may accidentally load GSAP multiple times in different places.
Best use cases
- Learning and experimenting inside Bricks
- Small to medium projects
- Page-specific animations
- Users who prefer builder-based workflows over theme development
Practical recommendation
For many Bricks users, a very sensible hybrid approach is:
- Load GSAP and plugins globally
- Add small page-specific animation code where needed
- Move larger reusable animation logic into a dedicated script later
This gives you simplicity and room to grow 📌
5. Adding GSAP with a plugin or code manager
Another option is to use a WordPress plugin that lets you inject scripts globally or conditionally.
This might be:
How it works
You paste CDN script tags or custom JavaScript into a plugin-managed area, often:
- Site-wide header
- Site-wide footer
- Specific pages
- Specific post types
- Conditional locations
Advantages
- No theme editing
- Easy for non-developers
- Can be safer than editing core theme files
- Useful if you do not want to touch PHP
Disadvantages
- Another plugin dependency
- May encourage “script dumping”
- Can become messy if overused
- Not always ideal for structured long-term development
Best use cases
- Quick implementation
- Projects where theme editing is restricted
- Users uncomfortable with
functions.php - Simple or transitional setups
Important warning
If you use plugins for script injection, be extra careful not to load:
- GSAP in the plugin
- GSAP again in Bricks
- GSAP again in the theme
That can cause confusion, wasted requests, and potential conflicts.
Comparing the methods
Here is the practical difference between the common approaches:
-
CDN only
Best for speed, learning, and quick tests
-
Local files + child theme enqueue
Best for professional, maintainable projects
-
Bricks custom code
Best for convenience and builder-centered workflows
-
Code injection plugin
Best when you want simplicity without editing theme files
-
Hybrid approach
Often the best real-world solution
A good hybrid setup might look like this:
- Load GSAP globally through the child theme or Bricks global custom code
- Load plugins globally only if widely used
- Put page-specific animation logic where it is easiest to manage
- Move repeated logic into reusable external JS files later
Which method should you choose as a BricksBuilder user?
If your JavaScript and CSS skills are still developing, the best path is usually not the most “developer-pure” one, but the one that is both safe and manageable.
I would recommend this progression:
-
Start with CDN + Bricks custom code
This is the easiest way to understand how GSAP works and create your first animations.
-
Move to global loading
Once you know you want GSAP site-wide, place GSAP in a single global location.
-
Graduate to child theme enqueueing
As your projects become more advanced, move to a cleaner WordPress-native setup.
This progression lets you learn without getting blocked by technical setup too early 🎯
Recommended setups by experience level
-
Absolute beginner
Use:
- CDN for GSAP
- Bricks custom code for your animation scripts
Why:
- Fastest setup
- Easiest to understand
- Minimal technical friction
-
Beginner to intermediate
Use:
- Global GSAP loading in Bricks
- Page-level or template-level custom JS where needed
Why:
- Cleaner than pasting scripts everywhere
- Still easy to manage
- Good balance of simplicity and structure
-
Intermediate and beyond
Use:
- Child theme
- Proper
wp_enqueue_script() - External custom JS files
Why:
- Better architecture
- Better reuse
- Better long-term maintenance
What “correct loading order” really means
This is one of the most important concepts in GSAP setup.
If your script runs before GSAP is available, you will get errors like:
gsap is not defined
If your plugin runs before GSAP core, the plugin may fail.
The correct dependency chain is:
- GSAP core
- Any GSAP plugins
- Plugin registration
- Your animation code
- Only after the DOM elements exist
Conceptually:
$$
\text{Working animation} \Rightarrow \text{library loaded first} \land \text{target exists when code runs}
$$
That is why many examples use:
document.addEventListener("DOMContentLoaded", function() {
// animation code here
});
This makes sure the page structure exists before your code tries to animate it.
A simple decision framework
If you are unsure which path to choose, use this checklist:
-
Do I just want to test GSAP quickly?
Choose:
- CDN
- Bricks custom code
-
Do I want a clean site-wide setup without editing theme files too much?
Choose:
- Bricks global custom code
- Possibly a code manager plugin
-
Do I want the most robust and scalable setup?
Choose:
- Child theme
- Local files or controlled external loading
wp_enqueue_script()
-
Do I only need animations on one or two pages?
Choose:
- Bricks page-level custom code
- But still avoid loading GSAP multiple times
My practical recommendation for your course path
Because you are using WordPress + BricksBuilder and you want to learn both GSAP and later Glaze, I would suggest this sequence:
-
First stage: easiest setup
- Add GSAP via CDN
- Add your custom test animation in Bricks
- Confirm GSAP works
-
Second stage: cleaner structure
- Load GSAP globally only once
- Keep custom animations organized by page/template
-
Third stage: professional setup
- Use a child theme
- Enqueue GSAP and plugins properly
- Store custom animations in dedicated JS files
This is ideal because it matches your learning curve:
- Understand the tool
- Use it comfortably
- Structure it professionally
Final takeaway
The “best” way to add GSAP to WordPress depends on your current level and project complexity.
In short:
- CDN is best for fast learning and testing
- Bricks custom code is best for convenience
- Child theme + enqueueing is best for long-term professional use
- Plugins are useful when you want convenience without editing theme files
- A hybrid setup is often the most practical real-world solution