PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 27, 2022

[FIXED] Can't get variables to work in Wordpress for Intercom Javascript

 January 27, 2022     intercom, javascript, php, wordpress     No comments   

Issue

Intercom provide the following snippet to be injected before the body tag:

<script>
  window.intercomSettings = {
    app_id: "",
    name: "<?php echo json_encode($current_user->name) ?>", // Full name
    email: "<?php echo json_encode($current_user->email) ?>", // Email address
    created_at: "<?php echo strtotime($current_user->created_at) ?>" // Signup date as a Unix timestamp
  };
</script>

However, it creates the launcher with an error; stating to check the email variable. What should the variable be for Wordpress?


Solution

It's not meant to be injected before body, it has to be before the body close tag .

<script>
  window.intercomSettings = {
    app_id: "",
    name: "<?=wp_get_current_user()->user_login?>", // Full name
    email: "<?=wp_get_current_user()->user_email?>", // Email address
    created_at: "<?=strtotime(wp_get_current_user()->created_at)?>" // Signup date as a Unix timestamp
  };
</script>
</body>


Answered By - TheDon
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing