wp_footer
Fires just before the closing </body> tag on front-end pages. Use it to print HTML or inline scripts at the end of the page.
When it fires
wp_footer runs when the theme calls wp_footer(), normally the last thing before . Classic themes call it in footer.php and block themes get it automatically. It doesn't fire in the admin area (use admin_footer) or on the login page (use login_footer).
At priority 20 WordPress prints the scripts that were enqueued for the footer. Output at the default priority 10 comes before those scripts; use a priority above 20 if your code needs them on the page first.
Parameters
None. Your callback takes no arguments.
Example: Add a Back to top link
add_action( 'wp_footer', function () {
printf(
'<a href="#top" class="back-to-top" style="position:fixed;right:1rem;bottom:1rem;">%s</a>',
esc_html__( 'Back to top', 'my-snippets' )
);
} );
Good to know
- If your inline script depends on an enqueued script, attach it with wp_add_inline_script() instead, so it always prints in the right place.
- If nothing appears, check that the theme calls wp_footer(). A theme without it also breaks many plugins.