gilgimech
gilgimech

Reputation: 21

Adding JavaScript to Shopify templates from an Custom Shopify App

Does anyone know if it's possible with the Shopify API to inject JavaScript code into Shopify template files like you can do using the Script Tags API with JavaScript files.

My goal is to have the app hit the server, get JavaScript code like <script type="text/javascript">console.log('App is running')</script> and inject that into every template page.

That way you wouldn't need to edit the themes template files.

I'm not looking for recommendations for books, tools, software libraries, and more. I want to know if it's possible to do this with the Shopify API.

Upvotes: 0

Views: 406

Answers (1)

David Lazar
David Lazar

Reputation: 11427

The short answer is yes. You can inject your Javascript into theme templates, because they are just that. Templates. Adding code to them is not difficult. You edit them with the API.

But if you did that, you'd be mangling the theme. If someone deleted your App, that mangling would remain.

So you do not do that. You get to stick with Script Tags.

You should re-think your strategy. Stick to what works, cleanly. I am pretty sure Shopify would hammer ban you anyway, but still, at least you know now.

Upvotes: 1

Related Questions