Last active
July 18, 2019 12:58
-
-
Save mucahitnezir/66ad071386f6f0328c5682306d9cdd14 to your computer and use it in GitHub Desktop.
Googe Tag Manager integration for wordpress websites. Replace your GTM code with YOUR-GTM-CODE in functions.php. Copy the contents of these files to active wordpress theme in your wordpress website.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Google Tag Manager Code For Head Tag */ | |
add_action('wp_head', 'wp_head_tag_manager'); | |
function wp_head_tag_manager() | |
{ | |
?> | |
<!-- Google Tag Manager --> | |
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': | |
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], | |
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= | |
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); | |
})(window,document,'script','dataLayer','YOUR-GTM-CODE');</script> | |
<!-- End Google Tag Manager --> | |
<?php | |
} | |
/* Google Tag Manager Code For Body Tag */ | |
add_action('after_body_open_tag', 'custom_content_after_body_open_tag'); | |
function custom_content_after_body_open_tag() | |
{ | |
?> | |
<!-- Google Tag Manager (noscript) --> | |
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=YOUR-GTM-CODE" | |
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> | |
<!-- End Google Tag Manager (noscript) --> | |
<?php | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html <?php language_attributes(); ?> class="no-js"> | |
<head> | |
<meta charset="<?php bloginfo( 'charset' ); ?>"> | |
<meta name="viewport" content="width=device-width"> | |
<link rel="profile" href="http://gmpg.org/xfn/11"> | |
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>"> | |
<?php wp_head(); ?> | |
</head> | |
<body <?php body_class(); ?>> | |
<!-- THIS IS IMPORTANT TO INSERT GOOGLE TAG MANAGER CODE --> | |
<?php do_action('after_body_open_tag'); ?> | |
<!-- OTHER HTML CODES --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your functions hook doesn't seem to be working.