Close Menu
Infoceptor
  • Business
  • Finance
  • Technology
  • Health
  • Life
  • More
    • Auto
    • Food
    • Health
    • Home
    • Space
    • Travel

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

What's Hot
Flywheel Logo

Flywheel review in 2023

June 8, 2023
Travel restrictions in Canada are different depending on where you're traveling from and to. Here's what you need to know before you go.

Canada: Traveling restrictions and what you need to know before you go

May 19, 2024
If you are planning a trip to Spain, there are some travel restrictions that must be taken into consideration.

Spain: Traveling restrictions and what you need to know before you go

May 19, 2024
Facebook X (Twitter) Instagram
Infoceptor
  • Business
    This guide will show you how to determine the value of your business using different business valuation methods.

    How to value you business – The ultimate guide for 2023

    May 9, 2024
    Have you ever thought of starting your own laundry service? Find out how with this easy guide.

    How to start a laundry service company in 2023

    May 5, 2024
    Learn about the best online payment solutions available to you. Check out what’s available, learn their pros and cons, and choose the one that best fits your needs.

    The 15 best online payment solutions in 2023

    April 27, 2024
    Learn how to create powerful backlinks for your website and increase your site's search engine ranking.

    How to build backlinks to your website

    April 25, 2024
    In this beginner's guide, we will show you the steps involved in creating a mobile app.

    Beginner’s guide on how to develop a mobile app

    April 24, 2024
  • Finance
    Learn how to build wealth and financial security. This article will share steps you can take to build a reliable cash reserve that will grow over time.

    Do you want to build wealth? Here are some ways to grow your money

    May 18, 2024
    Want to know your tax bracket? Check out our article for an overview of the different brackets and what you can expect to pay in 2022.

    Understanding IRS tax brackets – here’s what you’ll pay in 2023

    May 14, 2024
    This article will cover the best electric vehicle battery stocks to buy and invest in.

    The 10 best EV battery stocks to buy in 2023

    May 9, 2024
    The 10 most active penny stocks to watch this year is a list of the most active penny stocks ranked by total volume.

    The 10 most active penny stocks to watch in 2023

    May 8, 2024
    These electric car stocks are making a lot of money and you should consider adding them to your portfolio.

    The best electric car stocks to buy in 2023

    May 8, 2024
  • Technology
    Flywheel Logo

    Flywheel review in 2023

    June 8, 2023
    This article provides a list of the top iPhone models available today. Each model is reviewed based on features, specifications, performance, design and price point.

    Top iPhone models we’ve tested and you should get

    May 17, 2024
    Find out everything you need to know about the Apple Airpods Pro, including their price, features and if they're worth buying.

    Are Apple AirPods Pro a great choice in 2023?

    May 17, 2024
    To help you find the best responsive WordPress themes, we analyzed more than 100 themes and found those that are currently trending.

    The best responsive WordPress themes in 2023

    May 16, 2024
    These sympathy gifts make a great way to show you care while they also help your loved ones get through the tough times.

    The 15 best sympathy gifts that will show you care

    May 15, 2024
  • Health
  • Life
    These sympathy gifts make a great way to show you care while they also help your loved ones get through the tough times.

    The 15 best sympathy gifts that will show you care

    May 15, 2024
    Water bottles are a great way to stay hydrated. This article is dedicated to the most popular water bottles of the year!

    The best water bottles of 2023

    May 10, 2024
    Learn 30 weird and fun facts that will make you question everything.

    30 weird and fun facts that will make you question everything

    May 10, 2024
    Find out which cities in the US are the best for quality of life by checking out this article.

    20 best cities for quality of life in the USA

    May 7, 2024
    There are many ways to print your designs on t-shirts. Check out our list of the best printing services that offer top-notch quality at affordable prices.

    The 10 best T-shirt printing services of 2023

    May 6, 2024
  • More
    • Auto
    • Food
    • Health
    • Home
    • Space
    • Travel
Facebook X (Twitter) Instagram
Trending
  • Flywheel review in 2023
  • Canada: Traveling restrictions and what you need to know before you go
  • Spain: Traveling restrictions and what you need to know before you go
  • Do you want to build wealth? Here are some ways to grow your money
  • Our in-depth review of the Always Pan
  • Top iPhone models we’ve tested and you should get
  • Are Apple AirPods Pro a great choice in 2023?
  • The best shower heads of 2023
Infoceptor
Home»Technology»WordPress»How to insert code into your WordPress website’s header and footer
WordPress

How to insert code into your WordPress website’s header and footer

Asih TirtaBy Asih TirtaFebruary 16, 20245 Mins Read
Facebook Twitter LinkedIn Reddit Telegram WhatsApp Pinterest Email
Share
Facebook Twitter LinkedIn

Often you may be asked to add code snippets in the <header> and <footer> section of your WordPress website.

For instance, when trying to integrate your site to Google Analytics, Facebook Pixel, or Google Search Console, you’ll have to insert code to your WordPress site’s header and footer.

Inserting code in WordPress <header> or <footer>

By default, WordPress doesn’t provide you with an option to insert code snippets into your site’s header and footer.

Therefore, if you want to add the code you have to either:

  • Add code to your WordPress header and footer with a plugin
  • Manually add code to your WordPress header and footer by editing your theme’s functions.php file

How to add code to your WordPress header and footer with a plugin

This is the most recommended methods to add code since its beginner-friendly.

For this article, we’ll use the Head, Footer and Post Injections plugin to show how a plugin can help you add code to your WordPress website’s header and footer.

Head, Footer and Post Injections plugin

Go to Plugins on your WordPress dashboard and search for Head, Footer and Post Injections.

Install and activate the plugin.

Settings

Once you’ve activated the plugin, you can now add code by going to Settings and selecting Header and Footer in your WordPress dashboard.

There are several tabs, but we are interested in the header and footer tab. You’ll notice that there are several boxes under the header and footer tab.

To add any of the webmaster tools code to your site’s header, you have to paste the code into one of the boxes under the <HEAD> SECTION INJECTION area:

  • Every page – This box adds the code snippet to the header of every single page on your site. You can add the Google Analytics tracking code to WordPress here.
  • Only home page – This box only adds code to the header of your WordPress homepage.

To add code to your site’s footer, you can scroll down to the BEFORE THE  </BODY> CLOSING TAG (FOOTER) and paste it into one of the options:

  • Desktop – despite the name, this adds the code snippet to the footer section for all users, no matter their devices. To limit it to desktop ensure to specifically check the box for Mobile.
  • Mobile – check this box if you want to add a different code snippet to the mobile responsive version of your WordPress site.

Add code to header and footer of Google AMP pages

The Head, Footer and Post Injections has an additional advantage that allows you to specifically add code snippets to the header and footer of the Google AMP versions of your pages.

Simply navigate and click on the AMP tab and paste your code snippet into the appropriate box:

A plugin lets you add code to your site’s header and footer easily and quickly. No worries about errors in case you edit your theme’s files. Also, the plugin will save your header and footer code in separate places, and so your code snippets will remain intact if you ever update or switch themes.

How to manually add code to WordPress header and footer

WordPress is built on PHP and if you are familiar with the PHP you can proceed to try to manually edit your theme’s functions.php file.

However, if you are not comfortable with editing PHP files, it is recommended that you stick with the plugin method.

While you can add code snippets directly to your header.php and footer.php files, a better way is to use your functions.php file and the appropriate WordPress hook.

This lets you keep all your snippets in one place and avoid modifying core theme files.

To add code to your header, use this 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(){
?>
PASTE HEADER CODE HERE


};

To add code to your footer, use this 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(){
?>
PASTE FOOTER CODE HERE


};

Add it to your child theme’s functions.php file (make sure you use a child theme. If you don’t, your code will disappear the next time that you update your theme).

To do this, you can either use an FTP client or the inbuilt WordPress file editor.

When in doubt use a plugin like Code Snippets, which most people find to be a more convenient way to manage code.

Using this plugin also ensures that you won’t lose your duplicate page functionality if you ever switch WordPress themes in the future.

Navigate to plugins, select add new and search for it and install it.

Once you have the Code Snippets plugin activated, navigate to snippets, select add new and then proceed to paste the code. Give it a title and save changes.

We hope with this guide you can now comfortably Insert code into your WordPress header or footer.

If you are a beginner, we recommend that you use the plugin method if the manual method seems too technical or challenging.

People also viewed:

How to create a coupon popup with WordPress How to edit the ‘Powered by WordPress’ text and link in the footer area How to clone WordPress pages and posts Fixing the 403 forbidden error on WordPress How to build an Ecommerce store with WordPress.How to build an Ecommerce store with WordPress
code footer header insert WordPress
Share. Facebook Twitter LinkedIn Reddit Telegram WhatsApp Pinterest Email
Previous ArticleHow to configure and use a WordPress website
Next Article How to speed up WordPress by disabling WP-cron
Asih Tirta

Asih is a Infoceptor Technology writer, she is passionate about how technology can serve people and improve lives. She helps run code camps for K to 12 to teach young girls how to code and open doors to careers in tech for women.

Related Stories

How to clone WordPress pages and posts

February 17, 2024

Fixing the 403 forbidden error on WordPress

January 1, 2024

How to create a coupon popup with WordPress

December 7, 2023

How to edit the ‘Powered by WordPress’ text and link in the footer area

March 31, 2022
Leave A Reply Cancel Reply

Connect
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
  • LinkedIn
  • Reddit
  • TikTok
Don't Miss
Flywheel Logo Reviews

Flywheel review in 2023

By Matthew Drummond

Flywheel is a fast-growing web host that offers high-performance WordPress hosting for agencies, designers, and developers.

Travel restrictions in Canada are different depending on where you're traveling from and to. Here's what you need to know before you go.

Canada: Traveling restrictions and what you need to know before you go

May 19, 2024
If you are planning a trip to Spain, there are some travel restrictions that must be taken into consideration.

Spain: Traveling restrictions and what you need to know before you go

May 19, 2024
Learn how to build wealth and financial security. This article will share steps you can take to build a reliable cash reserve that will grow over time.

Do you want to build wealth? Here are some ways to grow your money

May 18, 2024
  • Auto
    • Auto Reviews
    • Electric
    • Insurance
  • Business
    • Company
    • Government
  • Entertainment
    • Movies
    • Music
  • Finance
    • Credit Cards
    • Crypto
    • Market
    • Personal Finance
  • Food
    • Coffee
    • Drinks
    • Holidays
  • Health
  • Beauty
  • Fitness
  • Food
  • Medical
  • Home
  • Backyard
  • Bathroom
  • Bedroom
  • Cleaning
  • Furniture
  • Home Office
  • Kitchen
  • Life
  • Astrology
  • Family
  • Fashion
  • Outdoors
  • Personal
  • Pets
  • Apple
  • Audio
  • Domain Names
  • Gaming
  • Google
  • Power
  • Reviews
  • Samsung
  • Destinations
  • Gear
  • Services
  • Space
  • Tourism
  • Technology
  • Tutorials
  • Web Hosting
  • WiFi
  • WordPress
  • Travel
  • Shopping
  • Sports
  • Work
  • Stocks
  • Television
  • Web Hosting
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn Reddit TikTok
© 2025 Infoceptor

Type above and press Enter to search. Press Esc to cancel.