Advertisement
Guest User

Untitled

a guest
Jan 31st, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. < ?php // ENVIAR AL DATALAYER SI ES CATEGORIA, PAGINA O HOME ?>
  2. < ?php if (is_singular('post')) : ?>
  3. <script>
  4. dataLayer=[{
  5.     'Fecha': '< ?php echo get_the_date(); ?>',
  6.     'Autor': '< ?php the_author_meta( 'ID' ); ?>',
  7.     'Titulo': '< ?php the_title(); ?>',
  8.     'Formato': '< ?php print get_post_format() ? : 'standard'; ?>',
  9. < ?php
  10. $categories = get_the_category();
  11. $separator = ', ';
  12. $output = '';
  13. if ( ! empty( $categories ) ) {
  14. foreach( $categories as $category ) {
  15. $output .= esc_html( $category->name );
  16.     break;
  17. }
  18. echo "'Categorias':'" . trim($output, $separator) . "'";
  19. }
  20. ?>
  21. }];
  22. </script>
  23. < ?php endif; ?>
  24. < ?php if (is_category()) : ?>
  25.     <script>
  26.     dataLayer=[{
  27.     < ?php
  28. $categories = get_the_category();
  29. $separator = ', ';
  30. $output = '';
  31. if ( ! empty( $categories ) ) {
  32. foreach( $categories as $category ) {
  33. $output .= esc_html( $category->name );
  34.     break;
  35. }
  36. echo "'Categorias':'" . trim($output, $separator) . "'";
  37. }
  38.     ?>
  39.     }];
  40.     </script>
  41. < ?php endif; ?>
  42. < ?php // FIN ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement