Liquid, JavaScript, themes, sales channels
l'm trying to add external CSS and Javascript to my website but I'm not sure how to. I'm not the most advanced with code so I've tried doing research but I'm still stuck. I have a Shopify theme, has anyone had any experience with this?
Like i said i'm not familiar with code so even when I write it I don't think it's right because once I put it back into the seo checker it stills says my javascript and css are not external
Hi @dayzia122,
Please go to Actions > Edit code > Layout > theme.liquid file, you can add the code directly here.
Or go to Assets, here contains all the CSS and JS files, you can add the code at each specific file.
Hope it helps!
How should it be written though?
Hi @dayzia122,
What code do you want to insert? Please send me the code, and I will check it.
I want to add this Javascript into my shopify website:
https://codepen.io/nickelse/pen/VqdEQg
The HTML part is already done on my Section "Announcement-bar.liquid"
The 4 Contents of the "swiper-content" are all together visible at my site (Test environment).
The CSS is also done.
The JS part i am struggling with..
I tried a few options:
1) Putting it also like this in "Announcement-bar.liquid"
Example:
<script>
// Global Swipe Function
function swiperGoodness() {
var mySwiper = new Swiper ('.swiper-container', {
// Optional Swimper Parameters
loop: true,
autoplay: { delay: 5000 }
})
};
// Run Function On Load
$(function(){
swiperGoodness();
})
// Run Function On Window Re-Size
$(window).resize(function() {
swiperGoodness();
});
</script>
2) Putting it also like this in a new Asset and call it from Theme.liquid
Example:
The new asset 'Test'
// Global Swipe Function
function swiperGoodness() {
var mySwiper = new Swiper ('.swiper-container', {
// Optional Swimper Parameters
loop: true,
autoplay: { delay: 5000 }
})
};
// Run Function On Load
$(function(){
swiperGoodness();
})
// Run Function On Window Re-Size
$(window).resize(function() {
swiperGoodness();
});
Theme.liquid
{{ 'test.js' | asset_url | script_tag }}
Unfortunately it all not worked out..
I don't have enough knowledge about how to put in the JS code..
Can somebody bring me on the right track?
User | RANK |
---|---|
22 | |
22 | |
10 | |
9 | |
6 |
Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023