Home » Hooks » wp_footer

The wp_footer hook is a WordPress action hook that is executed in the footer of the site. It is used to add code or scripts to the bottom of the page, just before the closing tag.

This hook is commonly used by WordPress developers to add Google Analytics tracking code, custom JavaScript, or other scripts to the website’s footer. It’s a great place to add functionality that needs to be loaded after the page content, but before the page is fully loaded.

Here is an example of how to use the wp_footer hook to add a custom JavaScript file to your WordPress site:

function my_custom_script() {
    wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom.js', array(), '1.0.0', true );
add_action( 'wp_footer', 'my_custom_script' );

This code will add the "custom.js" file located in the "js" directory of your theme’s folder to the footer of your WordPress site. Note that the ‘true’ parameter in the wp_enqueue_script function tells WordPress to load the script in the footer of the site.

Overall, the wp_footer hook is an essential tool for WordPress developers that allows them to add custom code and functionality to the bottom of their site’s pages.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.