We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

How to include Javascript or a Web Component in Policy Pages

How to include Javascript or a Web Component in Policy Pages

Mikael
Shopify Partner
1 0 0

Hi, I'm looking to be able to customize a Policy Page. This includes the ability to add some Javascript or even a Web Component to the policy page

I've gone to the policy settings and edited the HTML for a policy to include a `script` tag or a web component, but they get stripped out. I also don't see a way to make changes to these pages from the "Edit Code" part of my theme. 

I've landed on including the script in my Footer and then adding logic to ensure it only runs on policy pages, but this is not an ideal or straightforward solution. Are there any other options?

 

I searched for other answers first, but it looks like previous threads aren't having any luck on this topic:
https://community.shopify.com/c/technical-q-a/how-can-i-insert-script-into-a-policy-page-on-my-ecomm...

 

https://community.shopify.com/c/technical-q-a/how-can-i-include-custom-javascript-on-policy-pages/td...

Reply 1 (1)

Made4uo-Ribe
Shopify Partner
10211 2427 3080

HI @Mikael

Please follow the instructions below
!. From you Admin page, go to Online Store > Themes
2. Select the theme you want to edit, click the three dots to edit code
3. Under the Layout folder, open the theme.liquid
4. Place this code below inside the <body> tag. Use the code below to inject your code your script. 

{% if request.path contains "policies"  %}
<script>alert("hello")</script>
{% endif %}

 

If this fixed your issue, Likes and Accept as Solution are highly appreciated. Coffee tips fuel my dedication.
Get experienced Shopify developers at affordable rates—visit Made4Uo.com for a quick quote!
Need THEME UPDATES but have custom codes? No worries, for an affordable price.