Yes you can do the same for the Facebook Pixels.
Alternatively, if you are not fond of coding, you can simply install "Insert Headers and Footers" plugin.
You can easily insert codes for the header or footer by using this plugin. Once installed, you can go to Settings > Insert Headers and Footers where you can insert the code in the designated areas.
Hope this helps.