Add Scripts to the FOOTER – wp_footer()

Adding code to the footer of your website is relatively safe.

What is added to wp_footer() will be ran just before the closing </body> tag of your site.

The Volatyl-Independent Way

If you would like to add scripts to wp_footer() 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 footer

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

or…

Add HTML to your footer

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

If you are adding PHP to wp_footer(), use the first method. Use the second method for anything else you may be adding.

Return to docs