How to add custom code in header / footer in WordPress

Uses:

  • Add google tracking code/google ads code/etc. in header.
  • There are needs to quickly add cdn link/javascript/jquery code in header/footer to fix and handle things.
  • We may also need to add CSS code in header of website.
  • It is requirements for many website owners to track their websites as demanded by various google and other online services.
  • Experts need it to add new functionalities and fix issues which otherwise don’t work in WordPress because of limited access in WordPress.

Risky other 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.

2) Download File manager app, go to Cpanel file manager or use FTP and search files of WordPress. You may want to create new file for javascript and link it to your website through functions.php file. These methods sometimes fail to work because of complexity and other restrictions of WordPress.

Other methods mentioned above need time and coding skills. It is not advised to use ‘Other’ methods if you are not an expert in WordPress because it can cause serious issues in website.

There are server or cache issues which don’t allow the editing in website to display on live website. One may incur theme coding standards/restriction which shall not directly allow to code in theme files, as per 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 or causes issues. In case you are not an expert and don’t want to use risky other methods and don’t want to waste so much time, etc., try the DIY quick method given below:

3) Use a ready-made WordPress plugin to add code directly in header/body/footer of WordPress website. You will find it is quick to do through this plugin, with proper instructions mentioned: https://ziscom.in/product/directly-insert-code-in-header-body-and-footer-in-wp/