Inserting custom code to WordPress Header/Footer

Inserting custom code to WordPress Header/Footer

Firstly let’s realize that inserting a code in header/footer of WordPress should be well thought as an illegitimate code may be a potential security risk.

But there are valid reason to insert legitimate code for the following reasons.

  • Tracking/Analytical code
  • Advertisement code
  • Social media sharing buttons
  • Other SEO code

When you want to edit in such scenario, you may need to edit the php files of your theme, directly. It is a high sensitive change. If you are not php aware, this is not an option for you.

Even if you know PHP, it is recommended to use a valid WP plugins. But there is another risk too. The plugin should be compatible with your WordPress version. As on when WordPress is updated, this plugin should be maintained and upgraded by the development team as well. So you need to choose a wise plugin.

Let’s see one of such plugin today – WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager (This is not a sponsored post). Login to your WordPress admin dashboard.

go to Plugins > Add New Plugin
Search and find WPCode plugin. Press Install Now button.
Press Activate Button to enable the plugin.

Plugin installation is completed. We shall see how to configure it to insert your preferred code.

Go to Plugins > Installed Plugins.
Go to WPCode Lite. click on Code Snippets.
You will land in Code Snippets page. The menu will be opened accordingly.
You will find two snippets are added and inactive. Let’s not worry about them. We shall add a new snippet by pressing ‘Add New’ button.
You will find several readymade templates. Click on a custom code snippet.
Insert your preferred code snippet to be inserted to the header/footer. I used the Real User Monitoring script. (not a sponsored post)
For better maintenance, you may tag it in a meaningful way.
Do not forget to activate and update it.

That’s all. You don’t have to go through the pain of editing the theme files manually. The code will be injected by the plugin. If you wonder, how can you get a Real User Monitoring for your own website, you may sign up for a trial at apac.eginnovations.com (not a sponsored post).

Compatibility:

  • WordPress 6.4.3
  • eG Innovations 7.2

This post is written as part of #WriteAPageADay campaign of BlogChatter