Tagged: x
-
AuthorPosts
-
February 3, 2017 at 10:13 am #1356873
I know this has been answered before, but it seems like Google has changed the way they like the code to be installed for tag manager.
There are two scripts that Google requires on every page – one in the head and one after the opening body tag.
Can you tell me how to access each of these on the front-end? I tried it in functions.php but got a 500 error. That was fun.
Thanks!
February 3, 2017 at 2:43 pm #1357179Hi there,
Thanks for writing in! You can setup a child theme (refer knowledge base section) first and then add the following codes into your child theme’s functions.php file.
To add anything into your WP Header section.
// Add Google Tag Manager Code in Head // ============================================================================= function my_custom_code1(){ ?> <!-- Replace this line with your code provided by google --> <?php } add_action( 'wp_head', 'my_custom_code1' );
To add a code after body tag.
// Add Google Tag Manager Code in Body // ============================================================================= function my_custom_code2(){ ?> <!-- Replace this line with your code provided by google --> <?php } add_action( 'x_before_site_begin', 'my_custom_code2' );
Hope that helps.
March 23, 2017 at 5:27 pm #1418294This technique places the tag manager on the 154th line of the head (on my site). Is there a way to place it closer to the opening of the head tag?
March 24, 2017 at 1:29 am #1418676Hi There,
You can give a propriety to the first function given above.
// Add Google Tag Manager Code in Head // ============================================================================= function my_custom_code1(){ ?> <!-- Replace this line with your code provided by google --> <?php } add_action( 'wp_head', 'my_custom_code1', 10 );
Notice the 10, the lower the closer to the
<head>
tag.Cheers!
-
AuthorPosts