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

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #533730

    av_admin_1984
    Participant

    Hello
    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 error

    would you please tell me how to do that?

    #533731

    av_admin_1984
    Participant

    Oh, 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

    #533734

    av_admin_1984
    Participant

    that code should be in head tag

    #533821

    Luke Nielsen
    Keymaster

    Hello,

    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

    #533982

    av_admin_1984
    Participant

    Hi 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 manager

    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 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 this

    #534409

    Luke Nielsen
    Keymaster

    Hello,

    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

Viewing 6 posts - 1 through 6 (of 6 total)