猿问

无法让变量在对讲机脚本的Wordpress中工作

内部通信器在正文标记之前提供要注入的以下代码段:


<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>

但是,它创建了带有错误的启动器;声明以检查电子邮件变量。字压的变量应该是什么?


哆啦的时光机
浏览 128回答 2
2回答

梦里花落0921

它不是在身体之前注射的,它必须是在身体关闭标签之前注射的。<script>&nbsp; window.intercomSettings = {&nbsp; &nbsp; app_id: "",&nbsp; &nbsp; name: "<?=wp_get_current_user()->user_login?>", // Full name&nbsp; &nbsp; email: "<?=wp_get_current_user()->user_email?>", // Email address&nbsp; &nbsp; created_at: "<?=strtotime(wp_get_current_user()->created_at)?>" // Signup date as a Unix timestamp&nbsp; };</script></body>

桃花长相依

通过上面的代码示例,内部通信为PHP提供的另一件事是,用于数组值而不是单个值。当我意识到我正在传递的电子邮件在呈现后看起来像这样时,我使用该示例遇到了同样的问题,这导致它中断。json_encode""user@example.com""如果仅使用单个值,请不要使用 。只需按原样通过即可。json_encode
随时随地看视频慕课网APP
我要回答