Trouble getting Adsense set up

Hi there,

I tried to get adsense up and running and need to insert the code into my header so that they can audit the site. I followed your previous advice in another thread where you said I should:

  • go to functions.php
  • insert (I have created a space between < and ! so it is visible here - it’s not like that on the sheet obviously):

add_action( ‘wp_head’, ‘add_head_script’ );
function add_head_script(){
?>
< !-- X -->
<?php
}

  • and in place of the X insert the code from Google.

I did all of this but received an email from Google saying that I have not done this correctly. Do you know where I have gone wrong here?

Thanks,
EW

Hey @riugn557,

Instead of adding code in functions.php give a try to this WP plugin : https://wordpress.org/plugins/simplest-adsense-ads-manager
This is really simple :slight_smile:
If you still want us to take a look at it then please share wp-admin login details via Secure Note.

Regards

Hi Rahul,

Thanks for the plugin suggestion - I’ve downloaded it but it isn’t immediately clear how I can use it to implement the code in the way that I need to here.

If I give you my login details and the code for the functions.php I need to implement in the Secure Note, would you be able to have a look for me?

Thank you,
EW

Hi There,

Please update your code to this:

/**
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 }

Add that on your child theme’s functions.php file.

To check if it is successfully added, visit your page then do a view-source (ctrl+u or cmd+u). Then look for your adsense code near the <head> if its there, then you know its successfully added.

The 3rd party plugin suggested is a straight forward path, navigate to Settings > Google Adsense, you’ll see areas there where you can place your ads.

Thanks,

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