shopify add javascript code example

Example 1: how to add jquery to shopify

<!-- Include jQuery in your theme.liquid file, between <head> tag  -->
  
  <head>
    <script
    src="https://code.jquery.com/jquery-3.4.1.js"
    integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
    crossorigin="anonymous">
  	</script>  
  </head>

Example 2: how to add title to wordpress php

// For website name in <title> tag
<?php wp_title(); ?>
  
// For the Post title within the loop
<?php the_title(); ?>

Example 3: how to add javascript in html

<script src="script.js"></script>

Example 4: custom js shopify

If I understand correctly, the asset_url filter is what you are looking for.

To include a JS file in a .liquid file, you use:

{{ 'script.js' | asset_url | script_tag }}

And a CSS file:

{{ 'style.css' | asset_url | stylesheet_tag }}