Below are WordPress code examples to use wp_footer WordPress hook to add a custom script or HTML before closing of body tags.
function add_this_script_footer(){ ?>
[YOUR JS CODE HERE] // HTML OR SCRIPT
<?php }
add_action('wp_footer', 'add_this_script_footer');
This function helps to call Google Analytics or any third-party code down below before closing the body tags.
It is recommended to add these custom functions inside the child theme to avoid code overwriting due to theme updates.