如果用户已登录,则在页脚中实现Java代码

时间:2017-10-17 作者:Md. Amanur Rahman

如果用户登录,我想将下面的javascript和php代码实现到页脚。

<script>
  window.intercomSettings = {
    app_id: "fbpqr48f",
    name: <?php echo do_shortcode(\'[IMS_username]\');?>, // Full name
    email: <?php echo do_shortcode(\'[IMS_useremail]\');?>, // Email address
    created_at: <?php echo do_shortcode(\'[IMS_userregdate]\');?>, // Signup date as a Unix timestamp
  };
  </script>
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic(\'reattach_activator\');ic(\'update\',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement(\'script\');s.type=\'text/javascript\';s.async=true;s.src=\'https://widget.intercom.io/widget/fbpqr48f\';var x=d.getElementsByTagName(\'script\')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent(\'onload\',l);}else{w.addEventListener(\'load\',l,false);}}})()</script>
我知道我可以使用is\\u user\\u logged\\u in(),但我不知道或不知道如何在echo中使用echo,因为您可以看到脚本代码已经有3个echo用于实现短代码。

 <?php  if ( is_user_logged_in() ) {
    echo \'I can paste the code here\';
} else {
    echo \'\'; 
}

?>
欢迎提出任何建议。。

1 个回复
最合适的回答,由SO网友:Dejan Gavrilovic 整理而成

你不需要回显你的脚本代码,你可以告诉你的页脚。要继续使用JavaScript的php文件if 用户登录时的语句:

<?php  if ( is_user_logged_in() ): ?>
    // Your JavaScript code here
<?php endif; ?>

结束

相关推荐

Recommended File Permissions

嘿,伙计们,我花了很长时间试图解决这个问题。我想知道WordPress中的文件权限应该是什么样子in order to use the autoupdate feature. 到目前为止,我的wordpress安装程序一直在询问我的FTP信息,我不想使用那种升级/安装方法,我想使用纯/直接PHP。某些上下文:Web服务器和php fcgi守护程序运行为www-data:www-data</wordpress安装位于/home/blaenk/sites/domain.tld/</首先,我read