Various methods to add custom code:
1) Go to Appearance > Theme editor and search file named header.php/footer.php, however many themes have kept these files complex and adding custom code may not work directly in header or footer file.
Above methods need time and coding skills. Sometimes there are server or cache issues which don’t allow the editing in website to display on live website and some times there are theme coding standards/restriction which may not easily allow you to code in theme files for the requirement. There is also high risk for an owner to mess up file structure and other code in WordPress files which can make website to stop work. In case the above methods fail for you or you don’t want to waste so much time, etc., try the DIY quick method given below:
3) Use a ready-made WordPress app to add code directly in header/body/footer of WordPress website. There is a ready-made plugin available to do it quickly with proper instructions mentioned: https://ziscom.today/product/directly-insert-code-in-header-body-and-footer-in-wp/