Printing content and adding a script to the footer are two different things.
If you want to add your banner html in the footer, you can use the wp_footer
hook that will trigger when you call the get_footer()
function from your theme.
You can simple echo your html (or load a template file).
function myplugin_wp_footer () {
echo '<div id="myplugin-cookie-banner">bla bla</div>';
// or you can use include() function to load a PHP script instead
}
add_action('wp_footer', 'myplugin_wp_footer');
Then you can add your JS script as suggested by @CRavon
function myplugin_cookie_privacy_script(){
wp_enqueue_script( 'myplugin-cookie-script', plugin_dir_url(__FILE__).'js/cookie-banner.js', [], true, true);
}
add_action('wp_enqueue_scripts', 'myplugin_cookie_privacy_script');
The last parameter of wp_enqueue_script
tells that your script will be added in the HTML at the end of the body.