wp_footeraction-hookWP 1.5.1

Fires in the page footer. Scripts, styles, and other assets are commonly included when this event fires. This is one of the main theme hooks.

In addition to themes, WordPress itself and many plugins actively use this event.

This event is triggered by the wp_footer() function of the same name, which is called in the theme's footer.php file.

Calling wp_footer() is mandatory for all WordPress themes (templates). It is done as follows:

    ...
	<?php wp_footer(); ?>
</body>
</html>

Many built-in WordPress functions fire during this event. For example, one of them adds scripts registered through wp_enqueue_script() that were configured to load in the footer.

What fires on this hook on the front end by default in WordPress:

add_action( 'wp_footer', 'wp_print_footer_scripts', 20 );
add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' );
add_action( 'wp_footer', 'wp_admin_bar_render', 1000 );

There is another similar event, wp_head. It is triggered by wp_head() in the document's HEAD section, in header.php.

Usage

add_action( 'wp_footer', 'wp_kama_footer_action' );

/**
 * Function for `wp_footer` action-hook.
 * 
 * @return void
 */
function wp_kama_footer_action(){
	// action...
}

Examples

#1 Add HTML to the footer

Suppose a popup's HTML must be added to every page:

<?php
add_action( 'wp_footer', 'my_popup', 30 );
function my_popup(){
	?>
	<div id="my_popup" class="popup mfp-hide">
		<div class="popup_inner">
			<div class="popup_body">
				<div class="popup_content"></div>
			</div>
		</div>
	</div>
	<?php
}

#2 Output custom JavaScript in the footer

This demonstrates how to output JavaScript at the end of the HTML on any site page:

## JavaScript at the end of the document.
add_action( 'wp_footer', 'hook_javascript', 99 );
function hook_javascript(){
	?>
	<script> alert('Page is loaded.'); </script>
	<?php
}

Or this can be used:

## JavaScript at the end of the document.
add_action( 'wp_print_footer_scripts', 'hook_javascript' );
function hook_javascript(){
	?>
	<script> alert('Page is loaded.'); </script>
	<?php
}

Changelog

Since 1.5.1 Introduced.

Where the hook is called

wp_footer()
wp_footer
wp-includes/general-template.php 3429
do_action( 'wp_footer' );

Where the hook is used in WordPress

wp-includes/block-supports/duotone.php 54
add_action( 'wp_footer', array( 'WP_Duotone', 'output_footer_assets' ), 10 );
wp-includes/blocks/image.php 315
add_action( 'wp_footer', 'block_core_image_print_lightbox_overlay' );
wp-includes/class-wp-customize-manager.php 1949
add_action( 'wp_footer', array( $this, 'customize_preview_settings' ), 20 );
wp-includes/class-wp-customize-nav-menus.php 1354
add_action( 'wp_footer', array( $this, 'export_preview_data' ), 1 );
wp-includes/class-wp-customize-widgets.php 1215
add_action( 'wp_footer', array( $this, 'export_preview_data' ), 20 );
wp-includes/class-wp-script-modules.php 447
add_action( 'wp_footer', array( $this, 'print_enqueued_script_modules' ) );
wp-includes/class-wp-script-modules.php 460
add_action( 'wp_footer', array( $this, 'print_script_module_translations' ), 21 );
wp-includes/class-wp-script-modules.php 463
add_action( 'wp_footer', array( $this, 'print_script_module_data' ) );
wp-includes/class-wp-script-modules.php 465
add_action( 'wp_footer', array( $this, 'print_a11y_script_module_html' ), 20 );
wp-includes/customize/class-wp-customize-selective-refresh.php 154
add_action( 'wp_footer', array( $this, 'export_preview_data' ), 1000 );
wp-includes/default-filters.php 367
add_action( 'wp_footer', 'wp_print_speculation_rules' );
wp-includes/default-filters.php 368
add_action( 'wp_footer', 'wp_print_footer_scripts', 20 );
wp-includes/default-filters.php 652
add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
wp-includes/default-filters.php 656
add_action( 'wp_footer', 'wp_enqueue_stored_styles', 1 );
wp-includes/default-filters.php 664
add_action( 'wp_footer', 'wp_maybe_inline_styles', 1 ); // Run for late-loaded styles in the footer.
wp-includes/default-filters.php 723
add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); // Back-compat for themes not using `wp_body_open`.
wp-includes/default-filters.php 780
add_action( 'wp_footer', 'the_block_template_skip_link' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_block_template_skip_link().
wp-includes/interactivity-api/class-wp-interactivity-api.php 1519
add_action( 'wp_footer', array( $this, 'print_router_markup' ) );
wp-includes/media.php 3152
add_action( 'wp_footer', 'wp_underscore_playlist_templates', 0 );
wp-includes/media.php 5314
add_action( 'wp_footer', 'wp_print_media_templates' );
wp-includes/script-loader.php 3843
add_action( 'wp_footer', $capture_late_styles, 20 );
wp-includes/theme-templates.php 117
remove_action( 'wp_footer', 'the_block_template_skip_link' );