do_action( 'wp_footer' )

Prints scripts or data before the closing body tag on the front end.


More Information

The wp_footer action is triggered near the tag of the user’s template by the wp_footer() function. Although this is theme-dependent, it is one of the most essential theme hooks, so it is fairly widely supported.

This hook provides no parameters. You use this hook by having your function echo output to the browser, or by having it perform background tasks. Your functions shouldn’t return, and shouldn’t take any parameters.

This hook is theme-dependent which means that it is up to the author of each WordPress theme to include it. It may not be available on all themes, so you should take this into account when using it.

When included, the default output for this function is the admin panel which will be shown in the top of the theme. It should be kept in the footer for every theme because most of the plugin bind their script files or functions to this hook.

This hook is an action which means that it primarily acts as an event trigger, instead of a content filter. This is a semantic difference, but it will help you to remember what this hook does


Top ↑

Source

File: wp-includes/general-template.php

View on Trac



Top ↑

Changelog

Changelog
Version Description
1.5.1 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 2 content
    Contributed by Steven Lin

    Example migrated from Codex:

    If you want to influence the moment that your hook is executed, you can append an integer as 3rd argument to add_action:

    <?php
    function your_function() {
        echo '<p>This is inserted at the bottom</p>';
    }
    add_action( 'wp_footer', 'your_function', 100 );
    ?>
    

    The higher the number, the lower the priority and as a result your hook will be executed further down the page. Enqueued scripts are executed at priority level 20.

  2. Skip to note 3 content
    Contributed by dudleynguyen

    In version 5.8 of wordpress the action do_action(‘wp_footer’) seems to be called after each widget on the new block based Widgets screen. I think add a condition in your function to limit this.

    <?php
    function wpdocs_your_function() {
    	if ( is_admin() ) {
    		return;
    	}
    
    	echo 'This is inserted at the bottom';
    }
    
    add_action( 'wp_footer', 'wpdocs_your_function' );
    ?>
    

You must log in before being able to contribute a note or feedback.