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

当我无权访问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;

所以我有一个包含登录表单的下拉菜单。 这来自aWP插件,因此我无法直接编辑代码。 现在,一旦我启用了所述插件,它就会在网站上显示。 我只希望它显示 is_user_logged_in code>是否为false。 我想出的解决方案是使用if语句检查用户是否登录,并根据情况显示一些文本或登录表单。 现在这个想法不起作用,因为登录表单将始终显示。 我的问题是,如果我无法访问HTML,可以在课程中添加一些CSS吗? 我到目前为止提出的代码如下所示。 p>

 &lt;?php 
if(is_user_logged_in()){
 / *注销函数* / 
}其他{
 / *应该改变的代码 CSS。  * / 
} 
?&gt; 
  code>  pre> 
 
 

现在显然我删除了注销功能,因为这里不需要它,它使代码看起来更干净。 p>

PS。 我们需要更改的类是.lorem,样式将显示:block / none; p> div>

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