• Resolved redactionseomdri

    (@redactionseomdri)


    Hello there, I did put a code in my function.php to install Google GTM. Here is the code

    function gtm_head(){
      ?>
        <!-- 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-XXXXXX');</script>
    <!-- End Google Tag Manager -->
        <!-- End Google Tag Manager -->
      <?php
    }
    add_action( 'wp_head', 'gtm_head', 1 );
    
    /**
     * Google Tag Manager script in <body> 
     */
    function gtm_body_open(){
      ?>
      <!-- Google Tag Manager (noscript) -->
    	<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
    	height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    	<!-- End Google Tag Manager (noscript) -->
      <?php
    }
    add_action( 'wp_body_open', ' gtm_body_open', 1 );

    But now there’s a line of error on my front website : Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘ gtm_body_open’ not found or invalid function name in /home/u161678441/domains/michaeldri.com/public_html/blog/wp-includes/class-wp-hook.php on line 308

    I looked in the class-wp-hook file but I don’t know what to do…. Since i’m not a pro in development… Here the section of code in the file :

    // Avoid the array_slice() if possible.
    				if ( 0 == $the_['accepted_args'] ) {
    					$value = call_user_func( $the_['function'] );
    				} elseif ( $the_['accepted_args'] >= $num_args ) {
    					$value = call_user_func_array( $the_['function'], $args );
    				} else {
    					$value = call_user_func_array( $the_['function'], array_slice( $args, 0, (int) $the_['accepted_args'] ) );
    				}
    			}
    		} while ( false !== next( $this->iterations[ $nesting_level ] ) );
    
    		unset( $this->iterations[ $nesting_level ] );
    		unset( $this->current_priority[ $nesting_level ] );
    
    		$this->nesting_level--;
    
    		return $value;
    	}

    Please can you tell me what to do with that ? ?? ?? ??

    What should I add ?

    I would be really thankful !!!

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The error is not in class-wp-hook.php. The error is caused by using add_action() with a callback that doesn’t exist. The message appears in class-wp-hook.php because that’s where it’s trying to run the callback.

    The specific reason you’re seeing this error is that you have an extra space here:

    add_action( 'wp_body_open', ' gtm_body_open', 1 );

    In front of gtm_body_open. Remove that and the error should go away.

    Thread Starter redactionseomdri

    (@redactionseomdri)

    Ok now I feel dumb…

    Thank you ! Resolved

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Warning: call_user_func_array()’ is closed to new replies.