3.3 Different ways to add GSAP to a WordPress site
WhenIf workingyou want to use GSAP in WordPress—especially together with WordPressBricksBuilder—there are several valid ways to include it. Which one is “best” depends on how comfortable you are with code, how reusable your setup should be, and BricksBuilderhow much control you want. 🎯
This topic is important because many animation problems are not caused by GSAP itself, but by how it was loaded, therewhen isit nobecomes singleavailable, corrector waywhere toyour addcustom GSAP.code runs.
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 ⚙️
Thefour main goal is always the same:
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:
Addadding GSAP via a CDN directly in the page or templateAddadding GSAPbygloballyhostingviatheWordPressfiles locallyenqueueingAddadding GSAP throughyoura code snippets/plugin-based workflow
For a WordPress + BricksBuilder user, you do not need to master all of them immediately. But you should understand the pros and cons of each, because later—when your projects grow—you may want to switch from a quick setup to a cleaner, more scalable one.
before we compare the methods: what does “adding GSAP” actually mean?
When you “add GSAP” to a website, you usually need to load:
ScrollTrigger
ScrollToPlugin
TextPlugin
others depending on your needs
your own custom animation code, which uses GSAP
A simple mental model is:
If this order is wrong, your code areasmay fail.
For example, this will only work if GSAP has already been loaded:
gsap.to(".box", {
x: 200,
duration: 1
});
And this will only work if both GSAP and ScrollTrigger are already loaded and registered:
gsap.registerPlugin(ScrollTrigger);
gsap.to(".box", {
scrollTrigger: ".box",
y: 100,
duration: 1
});
So whenever we discuss “ways to add GSAP,” we are really discussing:
You do not need to use all of them. Usually, you will pick one main strategy and stay consistent.
1.method Adding1: adding GSAP via CDN directly in a page, template, or code block
This is usually the fastest way to get started. 🚀
A CDN (Content Delivery Network) is onea ofhosted URL from which the fastestbrowser andloads easiesta waysJavaScript to start.file. Instead of storing GSAP files ininside your WordPress installation,theme, you loadlink themto it from an external URL.source.
Howhow itthis works
You includeplace a <script> tag thatsomewhere pointsin toyour thesite GSAP file hosted elsewhere,output, for example:
<scriptIf you need
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 your own animation script comes after both:
<script>
document.addEventListener("DOMContentLoaded", function() {
gsap.to(".box", {
y:x: -50,200,
duration: 1
});
});
</script>
Why beginners like this method
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 wantneed 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
IfScrollTrigger, 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
Important loading order
If using CDN, alwaysalso load in this order:
For example:that:
<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(to(".hero-title"box", {
scrollTrigger: ".box",
y: 60,
opacity: 0,100,
duration: 1
});
});
</script>
where
2.you Hostingmight GSAPdo locallythis on yourin 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 worksBricks
InsteadPossible ofplaces linking to an external CDN URL, you load a file from your own site, such as:include:
<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
- Bricks
FullpagecontrolsettingsoverorfilesYou 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, andtemplate-level custom code more cleanly.
Disadvantages
Slightly more setup work
You need to upload files and reference them correctly.
RequiresCode basicelement filein organization
You should understand where theme files live and how WordPress loads assets.
Version updates are manual
If you want a newerplugin GSAPthat version,allows youheader/footer must replace the files yourself.
Best use cases
Recommendedwhy approachbeginners often like this method
IfBecause it is:
You can create a section in Bricks, give it a class like .box, paste in a script, and immediately see something move.
advantages
very easy to start
good for experiments
page-specific loading
disadvantages
harder to maintain
dependency/order issues
ScrollTrigger is loaded after your code, it breaks
not ideal for larger projects
possible duplication
when to use it
Use this method if:
when not to use it
Avoid relying on this as your long-term default if:
practical recommendation
For a beginner in BricksBuilder, this is an excellent sandbox method. Learn here first. But do not assume it is always the best production architecture.
method 2: adding GSAP regularly,properly via WordPress enqueueing
This is the WordPress-native way, and in many cases the best long-term solution ✅
WordPress has a built-in system for loading CSS and JavaScript files called enqueueing. Instead of manually printing <script> tags wherever you want, you tell WordPress which scripts to load, and WordPress handles output and ordering more cleanly.
why enqueueing matters
When scripts are enqueued properly, WordPress can better manage:
This makes your setup more robust.
a basic example
You would typically add this to your theme’s functions.php file, or better, to a child theme:
function mytheme_enqueue_gsap() {
wp_enqueue_script(
'gsap',
'https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js',
array(),
'3.12.5',
true
);
wp_enqueue_script(
'gsap-scrolltrigger',
'https://cdn.jsdelivr.net/npm/gsap@3/dist/ScrollTrigger.min.js',
array('gsap'),
'3.12.5',
true
);
wp_enqueue_script(
'my-gsap-animations',
get_stylesheet_directory_uri() . '/js/animations.js',
array('gsap', 'gsap-scrolltrigger'),
'1.0',
true
);
}
add_action('wp_enqueue_scripts', 'mytheme_enqueue_gsap');
Your custom animation code would then live in a separate file, for example /js/animations.js:
gsap.registerPlugin(ScrollTrigger);
gsap.to(".box", {
scrollTrigger: ".box",
y: 100,
duration: 1
});
what this code means
Let’s unpack it carefully:
wp_enqueue_script(...)
'gsap'
'https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js'
array()
'3.12.5'
true
For ScrollTrigger, this line matters a lot:
array('gsap')
That tells WordPress:
“Load
ScrollTriggeronly aftergsaphas loaded.”
And here:
array('gsap', 'gsap-scrolltrigger')
you tell WordPress:
“Load my animation file only after both GSAP core and ScrollTrigger are available.”
That is one of the bestbiggest long-termadvantages methodsof ✅enqueueing.
advantages
3.
cleaner structure
Thisbetter dependency management
more scalable
easier maintenance
closer to professional practice
disadvantages
WordPress-nativerequires waysome PHP
slower to doset itup properly.initially
Instead
you useneed WordPressfile functions to enqueue scripts.
Why enqueuing matters
In WordPress, scripts should ideally be added using wp_enqueue_script(). This gives WordPress better control over:access
Dependencieschild themeLoadingthemeordereditorFooterSFTPloadingor hosting file managerVersioninga code snippets workflow that supports this logic
when to use it
This is ideal if:
important best practice: use a child theme
If you place code directly in a parent theme and later update the theme, your changes may be overwritten. 😬
So if you are editing functions.php, it is usually safer to do so in a child theme.
conditional loading
A very useful improvement is to load GSAP only on pages that actually need it.
Example:
function mytheme_enqueue_gsap() {
if (!is_page('landing-page')) {
return;
}
wp_enqueue_script(
'gsap',
'https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js',
array(),
'3.12.5',
true
);
wp_enqueue_script(
'my-gsap-animations',
get_stylesheet_directory_uri() . '/js/landing-page-animations.js',
array('gsap'),
'1.0',
true
);
}
add_action('wp_enqueue_scripts', 'mytheme_enqueue_gsap');
This means:
landing-page, stop immediately
otherwise, load GSAP and your animation file
This is thecleaner professionalthan wayloading toeverything loadsite-wide scripts.when only one page needs it.
Example
using
method functions.php
3: adding GSAP through a code snippets plugin or script management plugin
HereThis is a cleankind exampleof middle ground between “quick and easy” and “properly structured.” ⚖️
Instead of editing theme files manually, you use a plugin that lets you insert PHP, JavaScript, or site-wide scripts in a managed interface.
Examples of plugin categories:
how this works
There are two main variations:
<script> tags globally
you add PHP that uses wp_enqueue_script()
The second is generally better if the plugin supports PHP snippets safely.
example: enqueueing GSAP through a snippets plugin
function mysite_enqueue_gsap() {
wp_enqueue_script(
'gsap',
'https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js',
array(),
'3.12.5',
true
);
wp_enqueue_script(
'gsap-scrolltrigger',
'https://cdn.jsdelivr.net/npm/gsap@3/dist/ScrollTrigger.min.js',
array('gsap'),
'3.12.5',
true
);
}
add_action('wp_enqueue_scripts', 'mysite_enqueue_gsap');
Then you might place your custom JS:
why this is attractive
For many WordPress users, especially non-developers, this is easier because:
advantages
safer than editing parent theme files
often easier for non-developers
can still be fairly organized
good transition step
disadvantages
depends on another plugin
can still become messy
sometimes less transparent
not always ideal for larger development workflows
when to use it
This is a strong option if:
a very practical beginner-friendly approach
A nice compromise can be:
That way, your library loading is centralized, but your small experiments remain easy to work with.
method 4: bundling GSAP in a custom theme or child theme workflow
This is the most “developer-style” approach and often the cleanest for serious projects 🛠️
Instead of relying on CDN links everywhere, you may keep your scripts in your project structure and load them through your theme or build process.
what this can mean
This can range from relatively simple to quite advanced:
For your current level, you probably do not need the advanced version yet. But it is good to understand the direction.
local file example
Suppose you store GSAP files inside your child theme:
/js/vendor/gsap.min.js
/js/vendor/ScrollTrigger.min.js
/js/animations.js
Then enqueue them:
function mytheme_enqueue_gsap_scripts(mytheme_enqueue_local_gsap() {
wp_enqueue_script(
'gsap',
get_stylesheet_directory_uri() . '/assets/js/vendor/gsap.min.js',
array(),
'3.12.5',
true
);
wp_enqueue_script(
'gsap-scrolltrigger',
get_stylesheet_directory_uri() . '/assets/js/vendor/ScrollTrigger.min.js',
array('gsap'),
'3.12.5',
true
);
wp_enqueue_script(
'custom-gsap-my-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'mytheme_enqueue_local_gsap');
WhyCDN thisvs local file: what is powerfulthe difference?
NoticeWith thea dependency arrays:CDN:
filesarray()forareGSAPloadedcorefrom an external serverarray('gsap')
With ScrollTriggerlocal files:
arearray('gsap',files'gsap-scrolltrigger')forserved from your ownscriptsite/theme
Neither is automatically “always better.” It depends on priorities.
CDN advantages
local file advantages
disadvantages of a custom theme workflow
when to use it
Use this if:
method 5: loading GSAP only where Bricks needs it
This tellsis WordPress:not a totally separate technical method, but rather an important strategy for WordPress + BricksBuilder projects.
A common beginner mistake is:
- load GSAP
firsteverywhere thenputloadallScrollTriggeranimation logic in one giant scriptthentargetloadmanyyourclassescustom animation file
So WordPress handles the order for you.
Advantages
Disadvantages
A
Best use cases
Important note for Bricks users
If you use BricksBuilder, this methodapproach 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:often:
Pageloadsettingsthecustomlibrarycodeglobally or conditionallyTemplate-levelkeepcustomanimation code grouped by template/page/componentSite-wideusecustomconsistentcode
This method is often the most approachable for non-developers because it avoids editing theme files.
Typical workflow
You might:
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
- one
VeryJSconvenientYou can manage code from inside the builder interface.
No need to edit theme files
This lowers the technical barrier significantly.
Greatfile 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
Practical recommendation
For many Bricks users, a very sensible hybrid approach is:
This givesbecomes youespecially simplicityuseful in Bricks because Bricks encourages visual building, and roomwithout structure your JS can become hard to growmap 📌back to the layout.
5. Adding GSAP with a pluginrealistic orcomparison 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:
Advantages
Disadvantages
Best use cases
functions.phpImportant warning
If you use plugins for script injection, be extra careful not to load:
That can cause confusion, wasted requests, and potential conflicts.
Comparingof the methods
Here is the practical differencecomparison betweenin theplain common approaches:language:
-
CDN
onlydirectly in page/templateBestfor - best
speed,for: learning,andtesting,quicksmalltestsone-off effects
LocalWordPress filesenqueueing +in theme/child theme enqueue
Best
Brickscode customsnippets/plugin-based codeloading
Best for convenience and builder-centered workflows
- best
Codefor:injectionuserspluginBest when youwho wantsimplicitystructure without editing theme files
Hybridcustom approachtheme/local asset workflow
Often
AIf goodI hybridwere setupadvising mightsomeone look like this:
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 recommendsuggest this progression:
Startstart with page-level CDN+ Bricks custom codeloadingThis is the easiest wayto understandhowGSAPworks and create your first animations.basics- then
Movemove toglobalsnippet/plugin-basedloadingenqueueingOnce you know you want GSAP site-wide, place GSAP in a single global location. - then
learn
Graduate tochild theme enqueueing
That learning path keeps your cognitive load manageable. 🧠
important technical details you should understand regardless of method
No matter which loading method you choose, a few concepts always matter.
1. load order
Your custom GSAP code must run after GSAP is available.
AsBad order:
Result: error such as gsap is not defined
Good order:
2. plugin registration
Some GSAP plugins should be registered before use:
gsap.registerPlugin(ScrollTrigger);
If you forget this, your projectsscroll-based becomeanimations moremay advanced,not movework correctly.
3. DOM readiness
Even if GSAP is loaded correctly, the elements you want to aanimate cleanermust WordPress-nativealso setup.exist when your code runs.
For example, this may fail if .box is not yet in the DOM at execution time:
gsap.to(".box", {
x: 200
});
A safer beginner pattern is:
document.addEventListener("DOMContentLoaded", function () {
gsap.to(".box", {
x: 200,
duration: 1
});
});
This says:
This progressionis letsespecially useful in WordPress because page builders, templates, and dynamic content can make script timing less obvious.
4. page builders can change markup
With BricksBuilder, what you learnsee withoutvisually is tied to generated HTML. If you later change:
your GSAP selector may stop matching.
So this selector:
gsap.to(".hero-title", {
y: 50
});
only works if an element with class .hero-title still exists on the front end.
That is why consistent class naming is very important.
5. avoid loading the same library multiple times
This is a surprisingly common issue.
For example:
functions.php
This can create debugging confusion. Even if it does not always break visibly, it is bad practice.
Try to keep a clear answer to the question:
“Where exactly is GSAP being loaded on this site?”
If you cannot answer that in one sentence, your setup may already be getting blocked by technical setup too early 🎯messy.
Recommendedrecommended setups byfor experiencedifferent levelskill levels
if
youAbsoluteare an absolute beginner
Use:
- CDN
for+GSAPpage-level script - maybe inside a Bricks code block or page custom code
for your animation scriptsarea
Why:
Fastestfastestsetupfeedback loopEasiesteasiesttoforunderstandlearning syntaxMinimalminimaltechnicalsetupfrictioncomplexity
But
keepBeginnerit limited to intermediateexperiments.
if you are a beginner who wants a cleaner real-site setup
Use:
Globala Code Snippets-style plugin to enqueue GSAPloading in BricksPage-levelaor template-levelseparate custom JS file if possible
Why:
Cleanersafer thanpastingeditingscriptsthemeeverywherefiles too earlyStillmoreeasymaintainabletothanmanagescattered inline scriptsGoodgoodbalancesteppingofstonesimplicitytowardandproperstructuredevelopment practice
if
Intermediateyou andare beyond
Use:
Childchild theme enqueueingProperwp_enqueue_script()
Why:
Bettercleaner architectureBettereasierreusemaintenanceBetterbetterlong-termscalability
recommended setup specifically for WordPress + BricksBuilder learners
For your situation, I would recommend the following staged approach:
phase 1: learn GSAP with the simplest possible setup
.box, .title, .button
phase 2: centralize library loading
phase 3: separate your animation logic
phase 4: move to child theme enqueueing when you feel ready
What “correct loading order” really means
This sequence is oneeffective because it respects the idea that learning has a kind of the“cost mostfunction” important concepts in GSAP setup.😊
If yourwe scriptthink runsof beforesetup GSAPdifficulty as $D$ and learning benefit as $B$, then for beginners you want a method where the ratio $\frac{B}{D}$ is available,as youhigh willas getpossible. errorsEarly like:
gsapsimple issetups notoften definedgive better Ifreturns; yourlater, plugincleaner runsarchitecture beforebecomes GSAPmore core, the plugin may fail.
The correct dependency chain is:
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.valuable.
Aa simple decision frameworkguide
If you are unsure which pathmethod to choose, use this checklist:rule of thumb:
-
DoI just want to test GSAPquickly?Choose: CDN
Do I want a clean site-wide setup without editing theme files too much?
Choose:
Do I want the most robust and scalable setup?
Choose:
wp_enqueue_script()Do I only need animations on one or two pages?
Choose:
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 setuptoday
Add GSAP viause CDN
Second stage: cleaner structure
ThirdI stage:want professionala safer no-theme-edit workflow
I want a clean long-term WordPress setup
Use ause child theme enqueueing
I andbuild plugins properly
This
common idealmistakes becauseto it matches your learning curve:avoid
Understandputting GSAP code before thetoollibrary is loadedUseforgettingittocomfortablyload or register plugins likeScrollTriggerStructureanimatingitselectorsprofessionallythat do not exist on the front end
Finalmy takeawaypractical recommendation in one sentence
TheFor “best”learning, waystart towith addCDN GSAP+ tosimple WordPress depends on your current page-level and project complexity.
In short: