By
05/13/2016   Comments Off on Add inline javascript to WordPress correctly

View all snippets

Add to functions.php file. Name the add_action whatever. You can also have the script load in the footer by changing wp_head to wp_footer.

// Add JS to Head
 
 add_action('wp_head','spd_add_cart_link');
 function spd_add_cart_link() { // break out of php ?>
 <script>
   // javascripts here
 </script>
 <?php } // break back into php

Source link