Add Scripts to the HEAD – wp_head()

People break things… plain and simple. So Volatyl is designed to do what a framework needs to do and allow individuals to take things further only if they choose to.

Adding code to the <head> of your WordPress site is one of those things you should do on your own and with care. Here’s how.

The Volatyl-Independent Way

If you would like to add scripts to wp_head() that will stay in place if you switch themes, the Insert Headers and Footers plugin works great.

The Volatyl-Dependent Way

Add the following code to the functions.php of your child theme!

Add PHP to your head

// Add scripts to wp_head()
function child_theme_head_script() {
	// Your PHP goes here
}
add_action( 'wp_head', 'child_theme_head_script' );

or…

Add HTML to your head

// Add scripts to wp_head()
function child_theme_head_script() { ?>
	<!-- Your HTML goes here -->
<?php }
add_action( 'wp_head', 'child_theme_head_script' );

Code added to wp_head() will be ran just before the closing </head> tag.

Return to docs