• Resolved sspiegelman

    (@sspiegelman)


    I am adding custom fields to the data layer through by adding this code to functions.php

    add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, “custom_dataLayer”);

    function custom_dataLayer( $dataLayer ) {

    $dataLayer[“price”] = get_field( ‘product_price’, false, false );
    $dataLayer[“name”] = get_field( ‘product_name’, false, false );

    return $dataLayer;
    }

    This worked fine but recently I am getting this error message:

    constant GTM4WP_WPFILTER_COMPILE_DATALAYER – assumed ‘GTM4WP_WPFILTER_COMPILE_DATALAYER’ (this will throw an Error in a future version of PHP) in functions.php on line 62

    Any idea why and how to fix it?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Thomas Geiger

    (@duracelltomi)

    Hi,

    What changes did you make on your hosting recently?
    Perhaps an upgrade in PHP? WP core upgrade?

    Thread Starter sspiegelman

    (@sspiegelman)

    I am hosting on Siteground. PHP 7.3.15 and WP 5.3.2.
    I believe PHP was recently upgraded but otherwise I don’t remember any changes.

    Thanks

    Plugin Author Thomas Geiger

    (@duracelltomi)

    What is you replace the constant to the string value 'gtm4wp_compile_datalayer'?

    Thread Starter sspiegelman

    (@sspiegelman)

    This seems to do the trick!

    Thanks!!

    add_filter( ‘gtm4wp_compile_datalayer’, ‘custom_dataLayer’);

    function custom_dataLayer( $dataLayer ) {

    $dataLayer[“price”] = get_field( ‘product_price’, false, false );
    $dataLayer[“name”] = get_field( ‘product_name’, false, false );

    return $dataLayer;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Error with GTM4WP_WPFILTER_COMPILE_DATALAYER’ is closed to new replies.