Adsense code location

Hello,

Where can i place google adense code in the header?
I don’t see the header location to place the code

rgds

Hello @tarekr,

Thanks for writing in! :slight_smile:

This has been answered by @friech in one of our threads. Please refer to:

Hope this helps.

Hello @tarekr,

Thanks for updating thread.

If you don’t want to use plugin to display ads, then you can add following code in child theme function.php file:

add_action( 'wp_head', 'add_head_script' );
function add_head_script(){
?>
     <!-- Add your adsense code below this -->
<?php
} 

You will have to install and activate the child theme for this so that you will not lose the changes you make when you update the parent theme. It is a good practice to use a child theme when building a site because you will have to add some custom stuff like this which is not native to the theme. I am sharing few resources that you can use to download and setup child theme.

https://theme.co/apex/child-themes

You can also take a look at following tutorial for more in depth information:

Thanks.

1 Like

thx.
I succeeded to add the code in the footer using PRO editor for footer.
I want to adjust the size of the ad to fit the footer size on mobile view. what i am seeing a space from top and bottom.
How can i fit the size of the ad to the footer size exactly?

Hello @tarekr,

Thanks for updating thread.

I think there must be issue with margin or padding in turn causing spacing. Can you please share website URL for us to take a closer look?

Thanks.

https://tarekrabaa,com

I deleted the footer.
The problem is that adSense code work when i added text to the footer provided that to add

tag with some text.
The problem is that the size of the ad is adjusting to the length i write in the P tag.
Regarding the padding and the margin i tried all the options and when i works i start getting an additional scroll bar.

I tried to use the widget in the footer. it doesn’t work at all with script AdSense

Any idea?

Hey There,

When using the widget in the footer, please do not use the text widget. You are supposed to use the Custom HTML widget because this would preserve any script tag or taw html code like from Google Adsense.

Hope this helps.

Hi,

The custom HTML doesn’t work at all with google Adsense. I tried

Hello there,

Sorry for the confusion. Kindly delete the Google Adsense code you’ve added on either Text or Custom HTML widget. I strongly suggest you follow @Prasant’s solution as this the best practice with regards to adding Wordpress plugin-like features. It would also be best if you share to us your code so you can just paste it on your child theme’s functions.php afterwards.

This is how the code will look like:

/**
Add adsense code
*/
add_action('wp_head','my_adsense', 1);
function my_adsense () { ?>

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

<?php }

Please take note that this is just an example.

Hope this helps.

i provided the code in secure note.
What i need is to add the Adsense in the footer with the ability the customize the size of the container in the footer.

Rgds

Hello There,

I have tested your code in our local testing servers and I con confirm that Adsense is not displaying anything. I have implemented it in my footer widgets and the adsense code were rendered by the page. It is just that no ads were displayed.

This could lead me to think that there are problems with your adsense code. Please check out the adsense documentation to troubleshoot the issue:
https://support.google.com/adsense/answer/1208336?hl=en

Hope this helps.

Hello,

I updated the code in the secure note. It is working ii tried it.

In the footer it is not working with the custom html widget

Hi there,

Have you created a responsive ad unit? Like from here https://support.google.com/adsense/answer/3213689?hl=en. As far as I recall, you’re only limited to the sizes of the ads you created, regardless of device or container, it will maintain the size you set in your ads setting. Hence there is also a responsive ad unit which is different, could you try that first?

And your Adsense works, it’s just not displaying which could be due to cache or google cache. I see this often even on other themes or plugins. I recommend contacting google expert about this.

Thanks!

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