disqus_如何在WordPress中的自定义帖子类型上禁用Disqus

disqus

We recently switched from WordPress comments to Disqus comment system on WPBeginner. One of our users pointed out that comments on our custom post types comments weren’t migrated properly. For a temporary solution, we simply disabled Disqus on certain custom post types. In this article, we will show you how to disable Disqus on custom post types in WordPress.

我们最近从WPBeginner上的WordPress注释切换到Disqus注释系统 。 我们的一位用户指出,关于自定义帖子类型评论的评论未正确迁移。 对于临时解决方案,我们只是对某些自定义帖子类型禁用了Disqus。 在本文中,我们将向您展示如何禁用WordPress中自定义帖子类型的Disqus。

Disqus not showing comments on our custom post types was an error on our part. When importing comment to Disqus, we couldn’t use the normal sync feature because of the size of our site. We had to generate an export file and send it to Disqus to pre-import the comments. This meant that we only did this for posts and not other post types. So when Disqus showed 0 comments on a custom post type item that had 50+ comments, it really was because Disqus didn’t know that it had any comments because we didn’t tell that to Disqus.

Disqus未对我们的自定义帖子类型显示评论,这是我们的错误。 将评论导入到Disqus中时,由于网站的大小,我们无法使用常规同步功能。 我们必须生成一个导出文件,并将其发送到Disqus以预导入评论。 这意味着我们仅针对帖子而不是其他帖子类型执行此操作。 因此,当Disqus在具有50多个评论的自定义帖子类型项目上显示0条评论时,这的确是因为Disqus不知道它有任何评论是因为我们没有告诉Disqus。

So in other words, if you were going to disable Disqus on custom post types because it didn’t work, then maybe you should check your import settings first. But if you want to disable Disqus on custom post types for some other reason, then follow along.

因此,换句话说,如果您因为不起作用而对自定义帖子类型禁用Disqus,那么也许您应该首先检查导入设置。 但是,如果由于其他原因要在自定义帖子类型上禁用Disqus,请遵循以下步骤。

影片教学 (Video Tutorial)

演示地址

If you don’t like the video or need more instructions, then continue reading.

如果您不喜欢该视频或需要更多说明,请继续阅读。

Before you make any changes make sure that you have enabled syncing between Disqus and WordPress. It is also recommended that you always make a complete WordPress backup of your site before making any big changes.

进行任何更改之前,请确保已启用Disqus和WordPress之间的同步。 还建议您在进行任何重大更改之前,始终对网站进行完整的WordPress备份

When you are ready, simply add this code in your theme’s functions.php file or a site-specific plugin.

准备就绪后,只需将此代码添加到主题的functions.php文件或特定站点的插件中


add_filter( 'comments_template' , 'wpb_block_disqus', 1 );
function wpb_block_disqus($file) {
if ( 'custom_post_type_name' == get_post_type() )
remove_filter('comments_template', 'dsq_comments_template');
return $file;

}

Don’t forget to replace custom_post_type_name with the name of your custom post type. This code simply adds a filter to check for a specific custom post type and disable Disqus comment template display.

不要忘记将custom_post_type_name替换为自定义帖子类型的名称。 这段代码只是添加了一个过滤器来检查特定的自定义帖子类型,并禁用Disqus评论模板显示。

We hope this article helped you disable Disqus on custom post types in WordPress. Also check out how we prevented Disqus from overriding Comments count in WordPress.

我们希望本文能帮助您禁用WordPress中自定义帖子类型的Disqus。 另请查看我们如何防止Disqus覆盖WordPress中的Comments count

If you liked this article, then subscribe to our YouTube Channel or join us on Twitter and Google+.

如果您喜欢这篇文章,请订阅我们的YouTube频道,或通过TwitterGoogle+加入我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-disable-disqus-on-custom-post-types-in-wordpress/

disqus

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值