How to Add Header and Footer Code in WordPress

Many tools and services like google adsense, Google Analytics, Facebook Pixel, Google Search Console, etc. Usually require adding code snippets to your sites header or footer in WordPress during integration.

By default, WordPress does not provide options for code insertion into the header and footer. And many WordPress users either find it difficult or uncomfortable to edit their Parent theme files directly. Luckily there is an easier solution for beginners.

So if you are struggling on how to add code to the WordPress footer or header. In this article, we will show you how to easily add code to the WordPress header or footer using the manual code method via the functions.php file.

How to Manually Add Code to Header and Footer WordPress

Keep in mind, if you want to use this method. It is important that you use a WordPress child theme to make your edits. Without the child theme, any code that you add to your parent theme’s header or footer will get overwritten on theme update.

Step 1: Header Code Snippet

* Describe what the code snippet does so you can remember later on */
add_action('wp_head', 'your_function_name');
function your_function_name(){

Step 2: Footer Code Snippet:

/* Describe what the code snippet does so you can remember later on */
add_action('wp_footer', 'your_function_name');
function your_function_name(){

Remember to change the following in each code snippet:

  • The comment description (helpful when you need to remember what a code snippet does a year later)
  • The your_function_name place-holder (both instances)
  • The PASTE X CODE HERE placeholder

When you are done customizing the above code snippets. You need to add them to the Child Theme functions.php file. This can be easily added via FTP. Or, through WordPress admin dashboard >> Appearance → Editor and select the functions.php file. Then, paste your code at the end of the file.

Google Analytics Code Integration

If you only wish to implement Analytics code, we strongly recommend using the free MonsterInsights plugin. The plugin also has a pro version. Which comes with lots of features that helps in conversion. It’s the best Google analytics plugin for WordPress. It gives you helpful stats without having to leave your WordPress dashboard. Get MonsterInsights Pro.

We hope this article helped you to learn how to Manually add header and footer code in WordPress.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.