Can I add javascript to a blog post?

New Member
1 0 0

Hi,

 

Like the title says, can you add javascript in a blog post. I'm trying to build a calculator and implementing it into my post. Thanks

0 Likes
Highlighted
Shopify Staff
Shopify Staff
320 30 51

Hi, @badhairdude!

 

This is May from Shopify, and welcome to our Shopify Community!

 

To answer your question, yes, you can add JavaScript in a blog post! You can take advantage of our Rich Text Editor (RTE) in order to add JavaScript. Before copy/pasting your code to the RTE, I highly suggest that your code is finalized, since the RTE will not notify you if you made any mistakes or will it show an output preview of your code. If you want to see a preview your code before adding it to your blogpost, I highly recommend using a third party compiler such as JSFiddle

 

When adding your code to the RTE, you'll want to make sure that you click on the '<>' button

and paste you code there. You will also want to make sure that you are wrapping your JavaScript code with a <script> tag and closing it with </script>. If you have any CSS code for styling, you'll also need to wrap it with a <style> </style> tag. It is important to note that since the RTE is already the <body> of the web page, please do not include opening tags such as <html><head><meta><title> and <body> inside your RTE. If you include these tags, the RTE will recognize the entire content as a string, and it will not compile your code properly. 

 

Here's an example of what your code should look in your RTE:

<script>
[Your JavaScript code here]
</script>

<style>
[Your CSS code here]
</style>

[Your body content here]

After you save your changes, depending on the code, you might need to adjust your theme code or settings, since it might interfere/overlap with your current theme code. For future reference, if you are seeing issues or unexpected results from your changes, I highly recommend reaching out to a Shopify Expert

 

Let me know if this helps! If you have any followup questions, feel free to reply back to this thread!

 

Cheers!

May | Social Care @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

0 Likes