Is there a way to append Javascript to the body in the script tag without using a file?
Normally you would do it with
wp_enqueue_script('name', 'path/to/js/file');
Is there a way to include js in the script tag directly?
Like:
<script>My awesome code </script>
2 Answers
Yes, you can directly insert what you want in the header or the footer using the action wp_head
or wp_footer
add_action('wp_head', 'custom_script');
function custom_script(){
?>
<script>My awesome code </script>
<?php
}
You only have to put this in functions.php of your child theme