[英]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.