How can I add a script to my header in my child theme?

I read an old post that suggested creating a child theme (which I’ve already done) and adding the script reference to the _header.php file in the “views/global” folder. There is no “_header.php” file in that folder in my parent “x” theme. So I’m lost. Please help.

I’m trying to add a script to my header file which needs to be before the close tag.

Thanks!

I found the solution by researching a similar topic. Hope this helps someone else…

add_action( ‘wp_head’, ‘add_head_script’ );
function add_head_script(){
?>

<?php
}

in the functions file.

Hi There,

Glad you sorted things out, and thank you for sharing. To iterate that for other users, the code should go to your child theme’s functions.php file.

/*Add script on the <head> of the site*/
add_action( 'wp_head', 'add_head_script' );
function add_head_script() { ?>

<!-- YOUR CODE HERE -->

<?php }

Cheers!

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.