Title: passing WordPress fields to data layer
Last modified: February 19, 2018

---

# passing WordPress fields to data layer

 *  [adamphord](https://wordpress.org/support/users/adamphord/)
 * (@adamphord)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-passing-wordpress-fields-to-data-layer/)
 * ok, this is driving me mental. this is the most basic thing in the world. and
   there is no help for it anywhere unless you’re a qualified programmer.
 * i am trying to pass my blog post info to google tag manager data layer but none
   of the functions work the way the documentation isnsits they do.
 * problems – nothing will pass any tag information, none of the suggested syntaxes
   work.
    can only pass author id as “1” (useless) – refusing to pass the author
   name full stop.
 * this is my code…
    <script> datalayer.push({ ‘month’: ‘<?php echo date(‘n’); ?
   >’, ‘year’: ‘<?php echo date(‘y’); ?>’, ‘author’: ‘<?php get_the_author(); ?>’,‘
   tags’: <?php the_tags(); ?> <?php $categories = get_the_category(); $separator
   = ‘, ‘; $output = ”; if ( ! empty( $categories ) ) { foreach( $categories as 
   $category ) { $output .= esc_html( $category->name ) . $separator; } echo “‘categories’:'”.
   trim($output, $separator) . “‘”; } ?> }); </script>
 * so tags doesn’t even create a blank variable in the data layer wtf, although 
   it does create the author variable, and simply refuses to populate it.
    if you
   change it to echo the_author(), the entire code breaks and we get no data layer
   values whatsoever. but if you change it to <?php get_the_author(); ?>’, we get
   the author field as blank. if we use get_the_author_meta then it returns a value
   of 1, get_the_modified_author also returns blank
 * why have all these similarly named and functioning field and no comparative document
   that shows how each is supposed to be used. i can’t even find anyone else’s code
   for doing this to copy and paste wtf?
 * and these are all the versions of any sort of proper syntax that are discoverable
   anywhere online and you seem to specifically need to be an actual coder to perform
   this extremely rudimentary function, and the online documentation around this
   is supremely unhelpful unless you already know the answer, and i just fume with
   rage at corporations that force me to interface with them like this. no help,
   no suppport, ask the community, see if anyone can be bothered replying. wait 
   wait wait, never mind if this has created a critical issue on your website because
   the support documentation is inadequate, just sit there in the dark mushroom 
   until some actual human being not actually even employed by the corporation that
   caused the problem volunteers to fix the issue in their spare time out of the
   goodness of their heart.
 * i am not an idiot. i know enough that i should never need help from the community
   if the help files are written by someone who understands both logic and the english
   language.
 * so thank you community for being here. stuff you wordpress for not having a standard
   help file for “how to pass any of our fields to tag manager”
 * this just m,akes me so angry. nobody should even be using wordpress without this
   information going to their analytics. wordpress should have fields that just 
   output what they flipping say they are. if get_the_author doesn’t get the author,
   what the hell does it actually do??
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhelp-with-passing-wordpress-fields-to-data-layer%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [adamphord](https://wordpress.org/support/users/adamphord/)
 * (@adamphord)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-passing-wordpress-fields-to-data-layer/#post-9988037)
 * also before anyone asks, yes I have tried doing the tags within the loop, but
   that still didn’t even return ‘tags’ as a variable in the data layer.
 *  Thread Starter [adamphord](https://wordpress.org/support/users/adamphord/)
 * (@adamphord)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-passing-wordpress-fields-to-data-layer/#post-9988039)
 * (that attempt basically involved replicating the entire syntax of the categories
   loop but with all references to categories/category changed to tags/tag
 *  Thread Starter [adamphord](https://wordpress.org/support/users/adamphord/)
 * (@adamphord)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-passing-wordpress-fields-to-data-layer/#post-9988045)
 * UPDATE – author problem solved, now just need help passing TAGS
 * Many thanks in advance.
 *  Thread Starter [adamphord](https://wordpress.org/support/users/adamphord/)
 * (@adamphord)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-passing-wordpress-fields-to-data-layer/#post-9988062)
 * Another Update, the issue is Tag Manager doesn’t like me using Tags as a varible
   name, if I change the variable name then I can get it to populate using get_the_tags
   but the output is formatted with HTML. How do I get it to just output the data?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘passing WordPress fields to data layer’ is closed to new replies.

## Tags

 * [author](https://wordpress.org/support/topic-tag/author/)
 * [Blog](https://wordpress.org/support/topic-tag/blog/)
 * [data layer](https://wordpress.org/support/topic-tag/data-layer/)
 * [gtm](https://wordpress.org/support/topic-tag/gtm/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 1 participant
 * Last reply from: [adamphord](https://wordpress.org/support/users/adamphord/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-passing-wordpress-fields-to-data-layer/#post-9988062)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
