How do I find the header where I can paste my Adsense code?

I applied for Adsense and was given a code to be pasted inside the head tag but I can’t find the header.php in the usual place I used to in my previous theme. I’m using the X child theme, ethos. If you could please give me the steps on how to go about this. I don’t know coding but if you can give me the steps on where to paste this, then I can do it.

The Adsense code looked something like this:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({
          google_ad_client: "ca-pub-235353453543534534",
          enable_page_level_ads: true
     });
</script>

Thanks!

Hi Sheina,

Thank you for reaching out to us. To add the Adsense code inside your head tag, just copy and paste the following code in your child theme’s functions.php file:

function google_adsense() { 
	?>
	<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
	<script>
		 (adsbygoogle = window.adsbygoogle || []).push({
			  google_ad_client: "ca-pub-235353453543534534",
			  enable_page_level_ads: true
		 });
	</script>
	<?php 
}

add_action('wp_head','google_adsense');

Let us know how this goes!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.