WordPress 登录可见评论模块WordPress 登录可见评论模块
这里我们要用到WordPress判断是否登录的函数:is_user_logged_in()
用判断函数把评论模块包裹起来就行了。
以WordPress默认主题Twenty Seventeen为例,打开主题正文模板文件single.php,找到类似的:
if ( comments_open() || get_comments_number() ) : comments_template(); endif;
修改为:
if ( is_user_logged_in()){
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
}之后,只有登录的状态下才能看见评论模块及评论内容。
其它主题方法类似,比如: