AdSense AMP Code

Hello!

I already found here where/how to paste my Google Adsense Code on post like this:


But now, I want to use AdSense AMP Code too.
Where or How can I do this?

This code goes to “head”

And this code goes to “Body”


Could you please help me with this?

Thanks a lot in advance

Hi @ElClements,

Thanks for writing in! First you need to setup a child theme (https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57) and then you can add the following codes into your child theme’s functions.php file and implement your codes accordingly

To add a script to your head, follow the example below.

/*Add script on the <head> of the site*/
add_action( 'wp_head', 'add_head_script' );
function add_head_script() { ?>

<!-- YOUR CODE HERE -->

<?php }

To add a code to Body, follow the example below.

// Add Script to Body
// =============================================================================
function add_script_to_body(){
?>

<!-- Insert Code Here -->


<!-- Insert Code Here -->

<?php 
}
add_action( 'x_after_body_begin', 'add_script_to_body' );
// =============================================================================

Hope that helps.

2 Likes

Thanks a lot for your help!

You are most welcome!

1 Like

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