Inserting google Adsense confirmation code

Hi,

I need to insert Adsense confirmation code into my site, but am at a total loss.

Firstly, I downloaded, installed and activated the child theme: https://theme.co/apex/child-themes

The first question is: should I keep the child theme activated at all times, or can I switch to the main Pro theme? The problem is (one of many, it seems), that I can not upload any images (and apparently not edit any .php files in the editor when the child theme is active).

Secondly, as I understand I need to add the Adsense code into the functions.php file. So I was able to do that by uploading it via ftp, but it is still waiting to be confirmed.

What should it look like? I just deleted the original contents of the file and added my Adsense code.

Then I read from the forums, that I need to paste this into the file:

function add_google_code(){ ?>

<?php } add_action('wp_head', 'add_google_code'); https://theme.co/apex/forums/topic/how-to-connect-google-adsense-under-the-html/ And then I saw this about inserting a script into the header in the child theme. add_action( 'wp_head', 'add_head_script' ); function add_head_script(){ ?>
<!-- Your adsense scripts will go here -->
<?php

}

The codes are somewhat different in both examples.

I gather that the Adsense code should replace all the " Insert the Google Code here " rows, or “Your adsense scripts will go here” Is that all there is? In that case, which of those answers is correct? Does the functions.php file need any other content, as the first time I tried (and am still waiting to see if it will fail, or will be confirmed), I uploaded it as a blank file with only my adsense code in it.

And then again, do I need to have the child theme active in order for it to work, and that Adsense would detect it? Apparently I can not have both the main theme and the child theme active at the same time.

I really want to get this fixed, as I have no idea how long it takes Adsense to confirm the code (apparently a lot), and it is pointless to blindly try different options simply to wait the same amount of time again.

Hi there,

Both of the code should work as they would function the same way, they are just coded differently.

You may use:

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.

Hope this helps.

1 Like

Thank You for the quick reply.

However, when I uploaded the file via ftp, (uploaded theme functions.php and a copy named functions.php) to the child theme folder, and now my entire website shows just a white screen. When I go to WP-Admin, I get the same white, blank screen.

There is nothing I can access, or do in my web browser.

Could it be that I tried to both deactivate and activate the child theme to see if it allowed me to post the code in the editor directly. Hint: It did not. So I uploaded the files via ftp, while the child theme was the main theme (i.e active, and the main theme being inactive). That move somehow screwed up the child theme and as the main theme is not active it will not load?

Edit: Apparently adding the functions.php files screwed it up. Deleted it, and it works normally.

So I assume the file is theme functions.php I needed to alter, not functions.php. Does the file name alter between different themes/child themes.I.e the X and Pro theme?

And also, which of the themes (main theme or child theme) do I need to keep active?

Hi there,

I am not sure what you did but installing the child theme is fairly straightforward.

First you will need to download the Pro child theme from here.

Once you have the zip file, you can go to Appearance > Themes > Add New then install the child theme.

After installing it, you will have to activate it.

Once it is activated, you can login to FTP and go to wp-content/themes/pro-child then you should see the functions.php file there.

Open the file and add the code suggested previously after the lines:

// Additional Functions
// =============================================================================

You will have to enable the child theme.

1 Like

Thanks.

For some reason I confused the file name (functions.php) with the title “Theme Functions”. That is where I got it wrong. Also, I thought I need to delete the entire contents to replace the code. But I took the original functions.php file from the Pro.zip file, added the code (keeping what was there), and uploaded it via ftp. :slight_smile:

No worries. :slight_smile:

Is everything working now?

It seems to work fine. :slight_smile:

As far as the Adsense confirmation goes, I guess I have to just wait. :stuck_out_tongue:

Glad to hear that. :slight_smile:

1 Like

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