The get_footer WordPress PHP action fires before the footer template file is loaded.
Usage
add_action('get_footer', 'your_custom_function', 10, 2); function your_custom_function($name, $args) { // your custom code here }
Parameters
- $name: string|null – Name of the specific footer file to use. Null for the default footer.
- $args: array – Additional arguments passed to the footer template.
More information
See WordPress Developer Resources: get_footer
Examples
Modify the footer based on a specific page
add_action('get_footer', 'modify_footer_for_about_page', 10, 1); function modify_footer_for_about_page($name) { if (is_page('about')) { $name = 'about-footer'; } return $name; }
Add extra content to the footer on the homepage
add_action('get_footer', 'add_extra_content_to_homepage_footer', 10, 0); function add_extra_content_to_homepage_footer() { if (is_home()) { echo '<div class="extra-content">Extra content for the homepage footer</div>'; } }
Show custom footer for logged-in users
add_action('get_footer', 'custom_footer_for_logged_in_users', 10, 1); function custom_footer_for_logged_in_users($name) { if (is_user_logged_in()) { $name = 'logged-in-footer'; } return $name; }
Add a dynamic footer based on the category
add_action('get_footer', 'dynamic_footer_based_on_category', 10, 1); function dynamic_footer_based_on_category($name) { if (is_category()) { $category = get_queried_object(); $name = 'footer-' . $category->slug; } return $name; }
Load a custom footer for a custom post type
add_action('get_footer', 'custom_footer_for_custom_post_type', 10, 1); function custom_footer_for_custom_post_type($name) { if (is_singular('your_custom_post_type')) { $name = 'custom-post-type-footer'; } return $name; }