Articles on: Publishers

How to add an Ad Tag to <head> section in WordPress

This article will guide you through Adding an Ad Tag to <head> section of your WP website process.

Request an Ad Tag from your Account Manager or grab it at our Dashboard

a. Login to EZmob Dashboard

b. Select Placements tab and Click at GET PLACEMENT


c. Click at COPY CODE

Here are 3 options of adding an ad tag to the <head> section of your WP website source code:
Use a Plugin
Edit a Theme Template
Use WP hook

You can choose the one most comfortable for you.
Let's describe them one by one.

Use a plugin


This method is the easiest and recommended for beginners.

Head, Footer and Post Injections
This is a free WP extension that adds code to the head itself.

To do this, first, install the plugin.

After activation, open the Settings > Header and Footer section in the admin panel and go to the Head and Footer tab.



The page of the selected tab has the <HEAD> page section injection block that we need.

There are 2 text fields here. The first is responsible for displaying the code in it on all pages of the site. The second adds code only on the main page of the WP site.



For your changes to take effect, be sure to click the Save button.

Edit a Theme Template


If you do not want to install additional plugins on your web resource, then the code in the head can be added manually in the desired template of your WordPress theme.

To do this, go to the wp-content/themes directory and find the header.php file

It is not recommended to modify the parent WordPress theme files. To do this, use the child. They allow you to make edits without fear that they will be lost the next time you update the theme.

The contents of the header.php file may differ for each theme. But its main blocks are similar.

For example, let's take the standard Twenty Twenty WP theme. If you open the specified file, then at the very beginning you will see the <head>…</head> block.



The required code must be added before the closing </head> tag.



Use WP hook


WordPress has a special hook that will add code to the <head>. To use it, open the functions.php file. This is the theme's main configuration file and is located at the root of the theme's folder . For example, for the specified theme, it is located at

/wp-content/themes/twentytwenty/functions.php

To add an Ad Tag to the site header, paste the code at the end of this file:

function wpplus_insert_header() {
?>
<!-- An Ad Tag -->
<?php
}
add_action( 'wp_head', 'wpplus_insert_header' );

Instead of <!-- An Ad Tag --> insert an Ad Tag copied at Step 1.

That's it!

Choose the easiest way via Plugin or Edit Theme manually and enjoy your earnings with EZmob monetization solutions

Updated on: 03/01/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!