Home › Forums › WoodMart support forum › Add tag manager/analytics / or any scripts in child theme
Add tag manager/analytics / or any scripts in child theme
- This topic has 5 replies, 2 voices, and was last updated 10 months, 2 weeks ago by Luke Nielsen.
-
AuthorPosts
-
January 26, 2024 at 1:36 am #533730
av_admin_1984ParticipantHello
Thanks to Luke Nielsen in this topic I got this code, and it works correctly
https://xtemos.com/forums/topic/split-how-to-change-breadcrumbs-headin-text/add_action( 'wp_body_open', function() { echo "<!-- Google Tag Manager (noscript) --> <noscript><iframe src='https://www.googletagmanager.com/ns.html?id=GTM-TNBSNHLC' height='0' width='0' style='display:none;visibility:hidden'></iframe></noscript> <!-- End Google Tag Manager (noscript) -->"; } ); add_action( 'wp_head', function() { echo "<!-- 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','GTM-TNBSNHLC');</script> <!-- End Google Tag Manager -->"; } );
Now I want to add another script to my child theme,
this is code (txt file attached), when I add it, it won’t save and the cpanel editor gives me an errorwould you please tell me how to do that?
January 26, 2024 at 1:37 am #533731
av_admin_1984ParticipantOh, your site won’t allow me to upload text file
Upload Errors: Push-Notification.txt: Sorry, you are not allowed to upload this file type.
this is my code:
<link rel="manifest" href="/manifest.json"> <!-- Najva Push Notification --> <script type="text/javascript"> (function(){ var now = new Date(); var version = now.getFullYear().toString() + "0" + now.getMonth() + "0" + now.getDate() + "0" + now.getHours(); var head = document.getElementsByTagName("head")[0]; var link = document.createElement("link"); link.rel = "stylesheet"; link.href = "https://van.najva.com/static/cdn/css/local-messaging.css" + "?v=" + version; head.appendChild(link); var script = document.createElement("script"); script.type = "text/javascript"; script.async = true; script.src = "https://van.najva.com/static/js/scripts/3710-website-46860-8fa4cb5e-4098-4c5d-8ec1-ae84e9d4b4d8.js" + "?v=" + version; head.appendChild(script); })() </script> <!-- END NAJVA PUSH NOTIFICATION -->
Thanks
January 26, 2024 at 1:40 am #533734
av_admin_1984Participantthat code should be in head tag
January 26, 2024 at 12:54 pm #533821
Luke NielsenKeymasterHello,
Use the below one code:
add_action( 'wp_head', function() { echo "<link rel='manifest' href='/manifest.json'> <!-- Najva Push Notification --> <script type='text/javascript'> (function(){ var now = new Date(); var version = now.getFullYear().toString() + '0' + now.getMonth() + '0' + now.getDate() + '0' + now.getHours(); var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'https://van.najva.com/static/cdn/css/local-messaging.css' + '?v=' + version; head.appendChild(link); var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true; script.src = 'https://van.najva.com/static/js/scripts/3710-website-46860-8fa4cb5e-4098-4c5d-8ec1-ae84e9d4b4d8.js' + '?v=' + version; head.appendChild(script); })() </script> <!-- END NAJVA PUSH NOTIFICATION -->"; } );
On my side works well: https://take.ms/TcEC3 , let me know the result.
Kind Regards
January 26, 2024 at 7:42 pm #533982
av_admin_1984ParticipantHi Luke, Thanks for the code
I need to combine this script with Google Tag Manager together not only this code!
I have this code for head and body to add google tag manageradd_action( 'wp_body_open', function() { echo "<!-- Google Tag Manager (noscript) --> <noscript><iframe src='https://www.googletagmanager.com/ns.html?id=GTM-TNBSNHLC' height='0' width='0' style='display:none;visibility:hidden'></iframe></noscript> <!-- End Google Tag Manager (noscript) -->"; } ); add_action( 'wp_head', function() { echo "<!-- 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','GTM-TNBSNHLC');</script> <!-- End Google Tag Manager -->"; } );
Now you send me a new code, I want to use that code in my child, how does it work?
Please check this https://xtemos.com/forums/topic/mobile-menu-not-working-woocommerce-8-5-1-woodmart-7-4-3/
I need immediate support for thisJanuary 29, 2024 at 11:04 am #534409
Luke NielsenKeymasterHello,
You can just add the last custom code to the child theme and it should work with other codes that are defined there before. You can be sure of that by checking it via the browser tools.
I will check that topic now. Let me know if you have any questions.
Kind Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register