Home › Forums › Front-end Issues › get_field not working in wp_footer › Reply To: get_field not working in wp_footer
Figured it out!
function google_tag_manager() {
global $wp_query;
?>
<?php if ( get_field('enable_google_tag_manager_code', $wp_query->post->ID) ) { ?>
<!-- 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','XXX-XXXXXXX');
</script>
<!-- Google Tag Manager -->
<?php } ?>
<?php }
add_action('wp_footer', 'google_tag_manager' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.