简体   繁体   English

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

[英]Add css in an if statement when I don't have access to the HTML

So I have a dropdown menu which contains a login form. 因此,我有一个包含登录表单的下拉菜单。 This comes from aWP plugin so I can't edit the code directly. 这来自aWP插件,因此我无法直接编辑代码。 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. 我只希望它显示is_user_logged_in是否为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. 我想出的解决方案是使用if语句检查用户是否登录,并根据情况显示一些文本或登录表单。 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? 我的问题是,当我无权访问HTML时是否可以在类中添加一些CSS? 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. PS。 The class we need to change would be .lorem and the styling would be display: block/none; 我们需要更改的类将是.lorem,样式将显示:block / none;

Change the .loginForm to your class or id of your loginf form. .loginForm更改为您的类或loginf表单的ID。

add_action('wp_head', 'my_function');

function my_function() {
    if (!is_user_logged_in()) {
        ?>
        <style>
            .loginForm {display: none}
        </style>
        <?php
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无权访问从php生成的HTML的id - I don't have access to the HTML's id that generate from php 如何在与数组元素匹配的子字符串中添加html i标签(如果它们没有标签) - How to add html i tag to sub-strings that matched the elements of the array if they don't already have the tag 无法访问Apache上的index.html? - Don't have access to index.html on apache? 在HTML CSS中使用绝对路径时,文件不会附加 - File don't get attached when I use absolute path in HTML CSS 使用HTTPS时,您无权访问此服务器上的/ - You don't have permission to access / on this server when using HTTPS 为什么我没有作用域来访问recursiveDirectoryItorator中的值? - Why don't i have scope to access values in a recursiveDirectoryItorator? 为什么我无法访问PHPExcel中的setReadDataOnly()或enableMemoryOptimization()? - Why don't I have access to setReadDataOnly() or enableMemoryOptimization() in PHPExcel? 当我无权访问PHP的本机FTP句柄时,如何使用PHP CLI自动执行FTP? - How do I use PHP CLI to automate FTP when I don't have access to PHP's native FTP handle? 使用 scandir() 时如何跳过我无权读取/访问的文件,以避免所有记录的错误? - How do I skip files which I don't have permission to read/access when using scandir(), to avoid all the logged errors? 不明白为什么如果声明没有{} - Don't understand why if statement doesnt have {}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM