douming4359 2015-09-07 11:39
浏览 50
已采纳

这可以提高效率吗?

I'm pretty green when it comes to php...really the only foray into the subject being working with wordpress. Regardless, I have been looking for a way to essentially echo a php statement such as below if, say the user is logged in. The following essentially echoes a logout link in wordpress.

<?php wp_logout_url( home_url());?>

Now, I can't just echo the above because the link needs to be customized, in this case, using an Icon from font awesome. Now, I need to essentially use the above as the HREF for an HTML link. I know after searching this site that echoing a php statement within a php statement is something you shouldn't do. I came up with the following and I'm wondering if there is a more effective method. This works by the way.

<?php if (is_user_logged_in()) { 
        $Logout =  wp_logout_url( home_url());
        echo '<a href="' . $Logout . '" id="addnewpost"><i class="fa fa-sign-out"></i></a>';
 }
      ?> 

Any advice would be appreciated.

  • 写回答

1条回答 默认 最新

  • douke6424 2015-09-07 11:57
    关注

    Not more effective but with a shorter code:

    <?=( is_user_logged_in() ? '<a href="' . wp_logout_url( home_url()) . '" id="addnewpost"><i class="fa fa-sign-out"></i></a>' : '') ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c