WordPress 登录才能查看评论模块

首页 » 实用教程 » WordPress 登录才能查看评论模块
所属分类:实用教程
发布时间:2020-02-17
浏览次数:3,469 views

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

之后,只有登录的状态下才能看见评论模块及评论内容。

其它主题方法类似,比如:

<?php if ( is_user_logged_in()){ ?>
<?php if ( comments_open() || get_comments_number() ) : ?>
	<?php comments_template( '', true ); ?>
<?php endif; ?>
<?php } ?>
关键字:

相关阅读

利用Robots.txt优化你的WordPress站点

很多建站新手对robots.txt文件的重要作用不是很清楚,利用这篇文章普及一下WordPress站点robo […]

Contact Form 7 消息收集插件 – Flamingo

Contact Form 7 表单插件默认是没有存储表单信息的功能的,都是直接发送到客户预先设置好的邮箱里,但 […]

WordPress定时发布——让搜索引擎和访客爱上你

预知未来的魅力 新浪微博的皮皮时光机很受欢迎,你是个微博funs,想吸引人气,又不想一次把肚子里的墨水吐干净, […]