As a website owner, you might be asked to add a line of code to your website. Sometime it is simple as adding it somewhere in the theme. But lets say you want to add web analytics software on your site. Programs such as Google Analytics and many others ask that you add code to your head tag on every page of a site.
The first thing you want to do is look for a plugin that will add the wanted code to your head tag. Just keep in mind, that the more plugins you add to WordPress, the slower your site will run. So if you have a lot of code to add to your site, look into the All-in-One-Webmaster Plugin if you are adding a bunch of analytic code.
If you have to many codes/scripts to add or you can not find a plugin that works, then you will have to add the code to the head tag yourself.
Adding code to the header of your WordPress Blog is easy. WordPress made it simple, by adding editor to your admin panel. The editor will allow you modify your theme’s code. To access the editor, Log in to your dashboard and good to your appearance section and select editor. Once you get into the editor you find a list of files that can be edited. You will need to select a file called header.php.
Once you open your header.php file, make sure to backup the code. Just copy your code and pasted it into a notepad file and save it. If you do not save the file and you overwrite the code, you will break your website. You will have to delete your theme and reinstall it or even worse, you might have to find the individual file and upload via FTP to get the right file in place.
Below is a screenshot of what my header file looks like.
In some themes, you may not have the option to update the header file. This could because you are using a child theme, such as StuidoPress. If this is the case with your theme, look for a plugin called Hooks or open hooks. Basically it adds custom fields to your dashboard to allow to modify your child themes without the worry modifying the original files.
Also keep in mind, your theme has an upgrade and you upgrade, then you will loose your changes to the files. Your best is to keep those codes in a notepad file with instructions on where the code goes you can easily add it back after the upgrades.
Image Source: Inconfinder