[英]How can I make content disappear when a user logs in?
我在Wordpress中工作,我想让用户登录后导航栏中的某些元素消失。我该怎么做?
You can use is_user_logged_in() to check if a user is logged in. 您可以使用is_user_logged_in()来检查用户是否已登录。
So if you put your html inside this code, it will disappear as soon as your user logs in: 因此,如果您将html放在此代码中,则该代码将在用户登录后立即消失:
if (!is_user_logged_in()) {
// your html, only for not logged users
}
You have to edit the plugin code and also understand the how the plugin works but you do it in another way a quite tricky but it works. 您必须编辑插件代码,还必须了解插件的工作方式,但是您要用另一种方式来完成它却很棘手,但它却可以工作。
add_filter('wp_head','my_js_code');
function my_js_code()
{
if (is_user_logged_in())
{
?>
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(".sfsi_widget").remove();
</script>
<?php
}
}
Write this code in functions.php and see if it works 在functions.php中编写此代码,然后查看是否有效
What I have done basically checks if user is logged in if yes performs javascript to remove that div of social plugin. 我所做的基本上是检查用户是否已登录(如果是)执行javascript来删除该社交插件的div。 if it will not work you have to
如果无法正常工作,您必须
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.