dongyou7739 2014-11-20 12:43
浏览 63
已采纳

当我无权访问HTML时,在if语句中添加css

So I have a dropdown menu which contains a login form. This comes from aWP plugin so I can't edit the code directly. Now once I enable said plugin it always shows on the website. I only want it to show if is_user_logged_in is false. The solution I came up with would be to use an if statement to check if the user is logged in or not and to show some text or the login form depending on the situation. Now this idea didn't work since the login form will always show. My question therefor would be if its possible to add some css to a class when I don't have access to the HTML? The code I came up with so far is noted below.

<?php
if ( is_user_logged_in() ) {
    /* The logout function */
} else {
    /* The code that SHOULD change the CSS. */
}
?>

Now obviously I removed the logout function since it's not needed here and it makes the code look cleaner.

PS. The class we need to change would be .lorem and the styling would be display: block/none;

  • 写回答

1条回答 默认 最新

  • dosryjij88555 2014-11-20 12:47
    关注

    Change the .loginForm to your class or id of your loginf form.

    add_action('wp_head', 'my_function');
    
    function my_function() {
        if (!is_user_logged_in()) {
            ?>
            <style>
                .loginForm {display: none}
            </style>
            <?php
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作