Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Ronald Huereca

    (@ronalfy)

    You can code in a filter.

    See this example in the FAQ.

    https://www.ads-software.com/plugins/metronet-tag-manager/other_notes/

    Thread Starter Zavo

    (@zavo)

    Hi Ronald,
    Thanks for the quick reply!
    Sorry, but I don’t understand this.

    I have custom fields on my post, for example, “Pro”.

    WordPress documentation custom fields says the function to retrieve the value of fields is as follows:
    get_post_meta($post_id, $key, $single);

    In your plug in, I entered:
    “Pro” under “Name”
    ” get_post_meta($post_id, $key, $single);” under “Value”

    But on the datalayer, it just outputs ” get_post_meta($post_id, $key, $single);
    “, it doesn’t actually run the function.

    I am interested in your plugin because I was told it allows to add custom fields data to the datalayer, but I can’t get it to work. Can you confirm that the plugin allows me to do it? If so, could you please explain how?

    Thank you!!

    Xavier

    Plugin Author Ronald Huereca

    (@ronalfy)

    Okay, this is just pseudo-code, but feel free to try it out.

    DataLayer variable name: pro
    DataLayer Value: {pro_value}
    Custom Field Key: Pro
    Custom Field Value: ????

    add_filter( 'gtm_pro_value', function( $all, $match, $post_id ) {
      return get_post_meta( $post_id, 'Pro', true );
    }, 10, 3 );
    Thread Starter Zavo

    (@zavo)

    Thanks, Ronald! But where do I enter this code?

    Plugin Author Ronald Huereca

    (@ronalfy)

    You should see a section below your post to input custom data layer variables.

    See: https://www.ads-software.com/plugins/metronet-tag-manager/screenshots/

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add custom fields to the datalayer’ is closed to new replies.