There are many cases you need to insert some lines of code into the header or body of your WordPress template.
What you can place into those areas:
- Add a meta tag to verify an external service like Google Webmaster Tool.
- Add Google Analytics script.
- A JavaScript script or import a script library.
- Custom stylesheet.
Creating a module for that purpose is overkill, so we will use a plugin.
Header and Footer Scripts
This plugin uses wp_head
 and wp_footer
 hooks and inserts your codes to the respective sections of the WordPress template.

The setting page has 2 fields for the user to input scripts in the header or footer. It also offers an option to input a custom script to an individual post or page.
Insert Headers and Footers
Insert Headers and Footers is also a simple plugin to insert code like Google Analytics, custom CSS, Facebook Pixel, and more to header and footer sections.

While the previous plugin allows script set in an individual post, this one allows the addition of content to beginning of the body tag.
It can be downloaded here.