Using WordPress ‘get_footer’ PHP action

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

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_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>';
  }
}
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_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;
}